Commit e654ed0f authored by Stefan Schuhbaeck's avatar Stefan Schuhbaeck
Browse files

Add loglevel switch to vadereConsole (close #132).

Move vadereConsole files to own package within simulation-module
parent 4f89a94b
...@@ -82,7 +82,7 @@ ...@@ -82,7 +82,7 @@
<configuration> <configuration>
<archive> <archive>
<manifest> <manifest>
<mainClass>org.vadere.simulator.entrypoints.VadereConsole</mainClass> <mainClass>org.vadere.simulator.entrypoints.cmd.VadereConsole</mainClass>
</manifest> </manifest>
</archive> </archive>
<descriptorRefs> <descriptorRefs>
......
package org.vadere.simulator.entrypoints; package org.vadere.simulator.entrypoints.cmd;
public enum SubCommand { public enum SubCommand {
......
package org.vadere.simulator.entrypoints; package org.vadere.simulator.entrypoints.cmd;
import net.sourceforge.argparse4j.inf.ArgumentParser; import net.sourceforge.argparse4j.inf.ArgumentParser;
import net.sourceforge.argparse4j.inf.Namespace; import net.sourceforge.argparse4j.inf.Namespace;
......
package org.vadere.simulator.entrypoints; package org.vadere.simulator.entrypoints.cmd;
import net.sourceforge.argparse4j.ArgumentParsers; import net.sourceforge.argparse4j.ArgumentParsers;
import net.sourceforge.argparse4j.impl.Arguments; import net.sourceforge.argparse4j.impl.Arguments;
...@@ -9,6 +9,13 @@ import net.sourceforge.argparse4j.inf.Subparser; ...@@ -9,6 +9,13 @@ import net.sourceforge.argparse4j.inf.Subparser;
import net.sourceforge.argparse4j.inf.Subparsers; import net.sourceforge.argparse4j.inf.Subparsers;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.vadere.simulator.entrypoints.Version;
import org.vadere.simulator.entrypoints.cmd.commands.MigrationSubCommand;
import org.vadere.simulator.entrypoints.cmd.commands.ProjectRunSubCommand;
import org.vadere.simulator.entrypoints.cmd.commands.ScenarioRunSubCommand;
import org.vadere.simulator.entrypoints.cmd.commands.SetLogLevelCommand;
import org.vadere.simulator.entrypoints.cmd.commands.SuqSubCommand;
/** /**
* Provides the possibility to start VADERE in console mode. * Provides the possibility to start VADERE in console mode.
* *
...@@ -20,7 +27,9 @@ public class VadereConsole { ...@@ -20,7 +27,9 @@ public class VadereConsole {
public static void main(String[] args) { public static void main(String[] args) {
ArgumentParser parser = createArgumentParser(); ArgumentParser parser = createArgumentParser();
// args = new String[]{"migrate", "--create-new-version", "0.6", "/home/lphex/hm.d/vadere/VadereSimulator/resources"}; // args = new String[]{"--loglevel", "OFF", "scenario-run", "-o", "/tmp", "-f", "/home/lphex/hm.d/vadere/VadereModelTests/TestOSM/scenarios/basic_2_density_discrete_ca.scenario"};
// args = new String[]{"-h"};
try { try {
Namespace ns = parser.parseArgs(args); Namespace ns = parser.parseArgs(args);
SubCommandRunner sRunner = ns.get("func"); SubCommandRunner sRunner = ns.get("func");
...@@ -39,6 +48,16 @@ public class VadereConsole { ...@@ -39,6 +48,16 @@ public class VadereConsole {
ArgumentParser parser = ArgumentParsers.newArgumentParser("Vadere") ArgumentParser parser = ArgumentParsers.newArgumentParser("Vadere")
.defaultHelp(true) .defaultHelp(true)
.description("Runs the VADERE pedestrian simulator."); .description("Runs the VADERE pedestrian simulator.");
parser.addArgument("--loglevel")
.required(false)
.type(String.class)
.dest("loglevel")
.choices("OFF", "FATAL", "ERROR", "WARN", "INFO", "DEBUG", "ALL")
.setDefault("INFO")
.action(new SetLogLevelCommand())
.help("Set Log Level for vadere.");
Subparsers subparsers = parser.addSubparsers() Subparsers subparsers = parser.addSubparsers()
.title("subcommands") .title("subcommands")
.description("valid subcommands") .description("valid subcommands")
......
package org.vadere.simulator.entrypoints; package org.vadere.simulator.entrypoints.cmd.commands;
import net.sourceforge.argparse4j.inf.ArgumentParser; import net.sourceforge.argparse4j.inf.ArgumentParser;
import net.sourceforge.argparse4j.inf.Namespace; import net.sourceforge.argparse4j.inf.Namespace;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.vadere.simulator.entrypoints.Version;
import org.vadere.simulator.entrypoints.cmd.SubCommandRunner;
import org.vadere.simulator.projects.migration.MigrationAssistant; import org.vadere.simulator.projects.migration.MigrationAssistant;
import org.vadere.simulator.projects.migration.MigrationException; import org.vadere.simulator.projects.migration.MigrationException;
import org.vadere.simulator.projects.migration.MigrationOptions; import org.vadere.simulator.projects.migration.MigrationOptions;
......
package org.vadere.simulator.entrypoints; package org.vadere.simulator.entrypoints.cmd.commands;
import net.sourceforge.argparse4j.inf.ArgumentParser; import net.sourceforge.argparse4j.inf.ArgumentParser;
import net.sourceforge.argparse4j.inf.Namespace; import net.sourceforge.argparse4j.inf.Namespace;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.vadere.simulator.entrypoints.ScenarioFactory;
import org.vadere.simulator.entrypoints.cmd.SubCommandRunner;
import org.vadere.simulator.projects.Scenario; import org.vadere.simulator.projects.Scenario;
import org.vadere.simulator.projects.ScenarioRun; import org.vadere.simulator.projects.ScenarioRun;
import org.vadere.util.io.IOUtils; import org.vadere.util.io.IOUtils;
......
package org.vadere.simulator.entrypoints; package org.vadere.simulator.entrypoints.cmd.commands;
import net.sourceforge.argparse4j.inf.ArgumentParser; import net.sourceforge.argparse4j.inf.ArgumentParser;
import net.sourceforge.argparse4j.inf.Namespace; import net.sourceforge.argparse4j.inf.Namespace;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.vadere.simulator.entrypoints.ScenarioFactory;
import org.vadere.simulator.entrypoints.cmd.SubCommandRunner;
import org.vadere.simulator.projects.Scenario; import org.vadere.simulator.projects.Scenario;
import org.vadere.simulator.projects.ScenarioRun; import org.vadere.simulator.projects.ScenarioRun;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
public class ScenarioRunSubCommand implements SubCommandRunner{ public class ScenarioRunSubCommand implements SubCommandRunner {
private final static Logger logger = Logger.getLogger(ScenarioRunSubCommand.class); private final static Logger logger = Logger.getLogger(ScenarioRunSubCommand.class);
@Override @Override
......
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.Logger;
import org.apache.log4j.Level;
import java.util.Map;
public class SetLogLevelCommand implements ArgumentAction {
@Override
public void run(ArgumentParser parser, Argument arg, Map<String, Object> attrs, String flag, Object value) throws ArgumentParserException {
Level level = Level.toLevel((String) value);
Logger.getRootLogger().setLevel(level);
}
@Override
public void onAttach(Argument arg) {
}
@Override
public boolean consumeArgument() {
return true;
}
}
package org.vadere.simulator.entrypoints; package org.vadere.simulator.entrypoints.cmd.commands;
import net.sourceforge.argparse4j.inf.ArgumentParser; import net.sourceforge.argparse4j.inf.ArgumentParser;
import net.sourceforge.argparse4j.inf.Namespace; import net.sourceforge.argparse4j.inf.Namespace;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.vadere.simulator.entrypoints.ScenarioFactory;
import org.vadere.simulator.entrypoints.cmd.SubCommandRunner;
import org.vadere.simulator.projects.Scenario; import org.vadere.simulator.projects.Scenario;
import org.vadere.simulator.projects.ScenarioRun; import org.vadere.simulator.projects.ScenarioRun;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
public class SuqSubCommand implements SubCommandRunner{ public class SuqSubCommand implements SubCommandRunner {
private final static Logger logger = Logger.getLogger(SuqSubCommand.class); private final static Logger logger = Logger.getLogger(SuqSubCommand.class);
@Override @Override
......
...@@ -93,7 +93,7 @@ public class ScenarioRun implements Runnable { ...@@ -93,7 +93,7 @@ public class ScenarioRun implements Runnable {
synchronized (scenarioStore) { synchronized (scenarioStore) {
logger.info(String.format("Initializing scenario. Start of scenario '%s'...", scenario.getName())); logger.info(String.format("Initializing scenario. Start of scenario '%s'...", scenario.getName()));
scenarioStore.getTopography().reset(); scenarioStore.getTopography().reset();
System.out.println("StartIt " + scenario.getName()); logger.info("StartIt " + scenario.getName());
MainModelBuilder modelBuilder = new MainModelBuilder(scenarioStore); MainModelBuilder modelBuilder = new MainModelBuilder(scenarioStore);
modelBuilder.createModelAndRandom(); modelBuilder.createModelAndRandom();
......
...@@ -5,6 +5,8 @@ import com.fasterxml.jackson.databind.JsonNode; ...@@ -5,6 +5,8 @@ import com.fasterxml.jackson.databind.JsonNode;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.vadere.simulator.entrypoints.cmd.SubCommand;
import org.vadere.simulator.entrypoints.cmd.VadereConsole;
import org.vadere.simulator.projects.migration.MigrationAssistant; import org.vadere.simulator.projects.migration.MigrationAssistant;
import org.vadere.tests.util.reflection.TestJsonNodeExplorer; import org.vadere.tests.util.reflection.TestJsonNodeExplorer;
import org.vadere.tests.util.reflection.TestJsonNodeHelper; import org.vadere.tests.util.reflection.TestJsonNodeHelper;
......
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