makefile in root; cli args; --help, --silent, --warnings

This commit is contained in:
Ondřej Hruška
2014-05-20 22:16:11 +02:00
parent 47e8cf419a
commit 9ca95838eb
4 changed files with 71 additions and 28 deletions
+4 -2
View File
@@ -70,6 +70,7 @@ public abstract class BaseApp implements AppAccess, UncaughtExceptionHandler {
private ResourceLoader resourceLoader = new AsyncResourceLoader();
private Level logLevel = Level.ALL;
public boolean sigleInstance;
private Level logSoutLevel;
public void setConfigFile(String filename, String comment)
@@ -136,9 +137,10 @@ public abstract class BaseApp implements AppAccess, UncaughtExceptionHandler {
}
public void setLogLevel(Level logLevel)
public void setLogLevel(Level logLevel, Level soutLevel)
{
this.logLevel = logLevel;
this.logSoutLevel = soutLevel;
}
}
@@ -229,7 +231,7 @@ public abstract class BaseApp implements AppAccess, UncaughtExceptionHandler {
final LogWriter log = Log.create(opt.logFilePrefix, new File(WorkDir.getDir(opt.logDir), opt.logFilePrefix + ".log"), opt.logArchiveCount);
Log.setMainLogger(log);
Log.setLevel(opt.logLevel);
Log.setSysoutLevel(opt.logLevel);
Log.setSysoutLevel(opt.logSoutLevel);
// connect slickutil to the logger
org.newdawn.slick.util.Log.setLogSystem(new SlickLogRedirector(log));
+45 -11
View File
@@ -6,7 +6,6 @@ import java.util.Arrays;
import java.util.logging.Level;
import mightypork.gamecore.core.BaseApp;
import mightypork.gamecore.logging.Log;
import mightypork.gamecore.util.files.OsUtils;
@@ -19,9 +18,10 @@ public class Launcher {
*/
public static void main(String[] args)
{
Log.f3("Arguments: " + Arrays.toString(args));
System.out.println("argv = " + Arrays.toString(args)+"\n");
boolean verbose = false;
Level llSyso = Level.FINER;
Level llFile = Level.ALL;
File workdir = null;
@@ -37,11 +37,27 @@ public class Launcher {
lwdDir = args[i + 1];
i++;
continue;
}
if (arg.equals("--verbose") || arg.equals("-v")) {
verbose = true;
} else if (arg.equals("--silent") || arg.equals("-s")) {
llSyso = Level.OFF;
continue;
} else if (arg.equals("--warnings") || arg.equals("-e")) {
llSyso = Level.WARNING;
continue;
} else if (arg.equals("--verbose") || arg.equals("-v")) {
llSyso = Level.ALL;
continue;
} else if (arg.equals("--help") || arg.equals("-h")) {
printHelp();
System.exit(0);
} else {
System.err.println("Unknown argument: " + arg);
printHelp();
System.exit(1);
}
}
@@ -51,14 +67,32 @@ public class Launcher {
workdir = new File(lwdDir);
}
} catch (final ArrayIndexOutOfBoundsException e) {
Log.e("Malformed arguments.");
} catch (final Exception e) {
System.out.println("Error parsing arguments:");
e.printStackTrace();
printHelp();
System.exit(1);
}
final BaseApp app = new RogueApp(workdir, true);
app.opt().setLogLevel(verbose ? Level.ALL : Level.FINER);
app.opt().setLogLevel(llFile, llSyso);
System.out.println("\nStarting the game...\n");
app.start();
}
private static void printHelp()
{
//@formatter:off
System.out.println(
"Arguments:\n" +
"\t--workdir <path>, -w <path> .... specify working directory\n" +
"\t--verbose, -v .................. print all messages\n" +
"\t--silent, -s ................... print no messages\n" +
"\t--warnings, -e ................. print only warning and error messages\n" +
"\t--help, -h ..................... show this help\n");
//@formatter:on
}
}