Commit c61a3946 authored by Benedikt Kleinmeier's avatar Benedikt Kleinmeier
Browse files

In "VadereConsole.java", added flag "--logname" to command line parser.

VadereSimulator/.../SetLogNameCommand.java:
- This file creates a new log appender (instead of redirecting the old ones).
- Therefore, it makes it robust against changes in corresponding "log4j.properties" files.

Fix #164
parent c6741320
...@@ -56,7 +56,14 @@ public class VadereConsole { ...@@ -56,7 +56,14 @@ public class VadereConsole {
.choices("OFF", "FATAL", "TOPOGRAPHY_ERROR", "TOPOGRAPHY_WARN", "INFO", "DEBUG", "ALL") .choices("OFF", "FATAL", "TOPOGRAPHY_ERROR", "TOPOGRAPHY_WARN", "INFO", "DEBUG", "ALL")
.setDefault("INFO") .setDefault("INFO")
.action(new SetLogLevelCommand()) .action(new SetLogLevelCommand())
.help("Set Log Level for vadere."); .help("Set Log Level.");
parser.addArgument("--logname")
.required(false)
.type(String.class)
.dest("logname")
.action(new SetLogNameCommand())
.help("Write log to given file.");
} }
private static void addSubCommandsToParser(ArgumentParser parser) { private static void addSubCommandsToParser(ArgumentParser parser) {
...@@ -74,12 +81,12 @@ public class VadereConsole { ...@@ -74,12 +81,12 @@ public class VadereConsole {
.required(true) .required(true)
.type(String.class) .type(String.class)
.dest("project-dir") .dest("project-dir")
.help("Path to project directory"); .help("Path to project directory.");
projectRun.addArgument("--scenario-file", "-f") projectRun.addArgument("--scenario-file", "-f")
.required(false) .required(false)
.type(String.class) .type(String.class)
.dest("scenario-file") .dest("scenario-file")
.help("Name of Scenario file"); .help("Name of Scenario file.");
projectRun.addArgument("--scenario-checker") projectRun.addArgument("--scenario-checker")
.required(false) .required(false)
.type(String.class) .type(String.class)
...@@ -91,7 +98,7 @@ public class VadereConsole { ...@@ -91,7 +98,7 @@ public class VadereConsole {
// Run Scenario // Run Scenario
Subparser scenarioRun = subparsers Subparser scenarioRun = subparsers
.addParser(SubCommand.SCENARO_RUN.getCmdName()) .addParser(SubCommand.SCENARO_RUN.getCmdName())
.help("Run scenario without a project") .help("Run scenario without a project.")
.setDefault("func", new ScenarioRunSubCommand()); .setDefault("func", new ScenarioRunSubCommand());
scenarioRun.addArgument("--output-dir", "-o") scenarioRun.addArgument("--output-dir", "-o")
.required(false) .required(false)
...@@ -110,7 +117,7 @@ public class VadereConsole { ...@@ -110,7 +117,7 @@ public class VadereConsole {
.required(true) .required(true)
.type(String.class) .type(String.class)
.dest("scenario-file") .dest("scenario-file")
.help("Scenario file to run"); .help("Scenario file to run.");
scenarioRun.addArgument("--scenario-checker") scenarioRun.addArgument("--scenario-checker")
.required(false) .required(false)
.type(String.class) .type(String.class)
...@@ -136,7 +143,7 @@ public class VadereConsole { ...@@ -136,7 +143,7 @@ public class VadereConsole {
.required(true) .required(true)
.type(String.class) .type(String.class)
.dest("scenario-file") .dest("scenario-file")
.help("Scenario files to run"); .help("Scenario files to run.");
// Run Migration Assistant // Run Migration Assistant
...@@ -176,7 +183,7 @@ public class VadereConsole { ...@@ -176,7 +183,7 @@ public class VadereConsole {
.action(Arguments.storeTrue()) .action(Arguments.storeTrue())
.dest("revert-migration") .dest("revert-migration")
.help("If set vadere will search for a <scenario-file>.legacy and will replace the current version with this backup." + .help("If set vadere will search for a <scenario-file>.legacy and will replace the current version with this backup." +
" The Backup must be in the same directory"); " The Backup must be in the same directory.");
migrationAssistant.addArgument("--recursive", "-r") migrationAssistant.addArgument("--recursive", "-r")
.required(false) .required(false)
...@@ -184,7 +191,7 @@ public class VadereConsole { ...@@ -184,7 +191,7 @@ public class VadereConsole {
.dest("recursive") .dest("recursive")
.setDefault(false) .setDefault(false)
.help("If PATH contains a directory instead of a scenario file recursively search " + .help("If PATH contains a directory instead of a scenario file recursively search " +
"the directory tree for scenario files and apply the command"); "the directory tree for scenario files and apply the command.");
migrationAssistant.addArgument("--create-new-version") migrationAssistant.addArgument("--create-new-version")
.required(false) .required(false)
...@@ -192,7 +199,7 @@ public class VadereConsole { ...@@ -192,7 +199,7 @@ public class VadereConsole {
.dest("create-new-version") .dest("create-new-version")
.help("Create new transformation and identity file based on current latest version" + .help("Create new transformation and identity file based on current latest version" +
"PATH must point to the directory containing the old transformation files." + "PATH must point to the directory containing the old transformation files." +
" This Argument takes the new Version Label as input"); " This Argument takes the new Version Label as input.");
} }
} }
package org.vadere.simulator.entrypoints.cmd.commands;
import net.sourceforge.argparse4j.inf.Argument;
import net.sourceforge.argparse4j.inf.ArgumentAction;
import net.sourceforge.argparse4j.inf.ArgumentParser;
import net.sourceforge.argparse4j.inf.ArgumentParserException;
import org.apache.log4j.*;
import java.util.Map;
public class SetLogNameCommand implements ArgumentAction {
@Override
public void run(ArgumentParser parser, Argument arg, Map<String, Object> attrs, String flag, Object value) throws ArgumentParserException {
String filename = (String) value;
RollingFileAppender appender = new RollingFileAppender();
appender.setName(filename);
appender.setFile(filename);
appender.setAppend(false);
appender.setMaxFileSize("10000KB");
appender.setLayout(new PatternLayout("%d{ABSOLUTE} %5p [%t] %c{1}:%L - %m%n"));
appender.activateOptions();
Logger.getRootLogger().addAppender(appender);
}
@Override
public void onAttach(Argument arg) {
}
@Override
public boolean consumeArgument() {
return true;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment