diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 71cc41e..c1f6197 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -2,7 +2,6 @@ image: heeroyui/scenarium-gitlabci:latest variables: JAVA_TOOL_OPTIONS: "-Dfile.encoding=UTF8" - #JAVA_HOME: "/usr/lib/jvm/java-14-openjdk/" before_script: - which javac diff --git a/src/io/scenarium/logger/Logger.java b/src/io/scenarium/logger/Logger.java index e513515..e95dd78 100644 --- a/src/io/scenarium/logger/Logger.java +++ b/src/io/scenarium/logger/Logger.java @@ -53,61 +53,69 @@ public class Logger { private static boolean haveColor = false; private static boolean isInit = false; + static { + // Load system color state + String value = System.getProperty("logger.color"); + if (value != null) + if (value.contentEquals("true") || value.contentEquals("1")) + haveColor = true; + else if (value.contentEquals("false") || value.contentEquals("0")) + haveColor = false; + else + System.out.println("error in color state '" + value + "' ==> not in range [true, false, 0, 1]"); + + // Load system debug level + value = System.getProperty("logger.level"); + if (value != null) { + LogLevel level = LogLevel.fromString(value); + System.out.println("Change global level at " + value + " ==> " + level); + Logger.defaultLevel = level; + } + } + private Logger() {} - public static void usage(String applicationName) { - Log.print("logger - help : "); - Log.print(" " + applicationName + " [options]"); - Log.print(" --logger-level= Change the default log level (set all Log level):"); - Log.print(" -3: debug None"); - Log.print(" -2: debug Print"); - Log.print(" -1: debug Todo"); - Log.print(" 0: debug Critical (default)"); - Log.print(" 1: debug Error"); - Log.print(" 2: debug Warning"); - Log.print(" 3: debug Info (default in debug)"); - Log.print(" 4: debug Debug"); - Log.print(" 5: debug Verbose"); - Log.print(" --logger-lib=name:X Set a library specific level:"); - Log.print(" name Name of the library"); - Log.print(" X Log level to set [0..6]"); - Log.print(" note: ':' can be replace with '/' or '+'"); - Log.print(" --logger-color Enable color in log (default in Linux/debug)"); - Log.print(" --logger-no-color Disable color in log (default in Linux/release and Other)"); - Log.print(" -h/--help: Display this help"); - Log.print(" example:"); - Log.print(" " + applicationName + " --logger-color --logger-level=2 --logger-lib=etk:5 --logger-lib=appl:5"); + public static void usage() { + Log.print(" [log]: Log session interface"); + Log.print(" --log-level= Change the default log level (set all Log level):"); + Log.print(" -3/none: debug None"); + Log.print(" -2/print: debug Print"); + Log.print(" -1/todo: debug Todo"); + Log.print(" 0/critical: debug Critical (default)"); + Log.print(" 1/error: debug Error"); + Log.print(" 2/warning: debug Warning"); + Log.print(" 3/info: debug Info"); + Log.print(" 4/debug: debug Debug"); + Log.print(" 5/verbose: debug Verbose"); + Log.print(" --log-lib=name:X Set a library specific level:"); + Log.print(" name Name of the library"); + Log.print(" X Log level to set [0..6]"); + Log.print(" !note!: ':' can be replace with '/' or '+'"); + Log.print(" --log-color Enable color in log"); + Log.print(" --log-no-color Disable color in log (default)"); + Log.print(""); } - -// private static void displayPackageDetails(final Package pkg) -// { -// final String name = pkg.getName(); -// out.println(name); -// out.println("\tSpec Title/Version: " + pkg.getSpecificationTitle() + " " + pkg.getSpecificationVersion()); -// out.println("\tSpec Vendor: " + pkg.getSpecificationVendor()); -// out.println("\tImplementation: " + pkg.getImplementationTitle() + " " + pkg.getImplementationVersion()); -// out.println("\tImplementation Vendor: " + pkg.getImplementationVendor()); -// } - public static void init(String applicationName, List args) { + /** + * Initialize the library with generic argument in command line + * @param args list of argument that are filtered after + */ + public static void init(List args) { if (isInit) return; isInit = true; - -// displayPackageDetails(Package.getPackage("dustin.examples")); - for (int iii = 0; iii < args.size(); ++iii) { String data = args.get(iii); - if (data.startsWith("--logger-level=")) { - String value = data.substring(15); + if (data.startsWith("--log-level=")) { + String value = data.substring(12); LogLevel level = LogLevel.fromString(value); System.out.println("Change global level at " + value + " ==> " + level); Logger.defaultLevel = level; - } else if (data.contentEquals("--logger-color")) + } else if (data.contentEquals("--log-color")) Logger.haveColor = true; - else if (data.contentEquals("--logger-no-color")) + else if (data.contentEquals("--log-no-color")) Logger.haveColor = false; - else if (data.startsWith("--logger-lib=")) { - String value = data.substring(13); + else if (data.startsWith("--log-lib=")) { + String value = data.substring(10); String[] values = value.split("/"); if (values.length != 2) { values = value.split(":"); @@ -121,16 +129,13 @@ public class Logger { } System.out.println("Change level of '" + values[0] + "' at " + LogLevel.fromString(values[1])); logLevels.put(values[0], LogLevel.fromString(values[1])); - } else if (data.contentEquals("-h") || data.contentEquals("--help")) - usage(applicationName); - else if (data.startsWith("--logger")) - Log.error("Can not parse the argument : '" + data + "'"); + } } // Clear all logger elements. int iii = 0; while (iii < args.size()) { String data = args.get(iii); - if (data.startsWith("--logger")) + if (data.startsWith("--log")) args.remove(iii); else iii++; diff --git a/test/src/test/scenarium/logger/TestBasicLog.java b/test/src/test/scenarium/logger/TestBasicLog.java index c989473..7c45921 100644 --- a/test/src/test/scenarium/logger/TestBasicLog.java +++ b/test/src/test/scenarium/logger/TestBasicLog.java @@ -24,33 +24,33 @@ public class TestBasicLog { @Test @Order(1) - public void firstInitialisation() { + public void aaFirstInitialisation() { List args = new ArrayList<>(); - args.add("--logger-level=999"); - args.add("--logger-level=1"); - args.add("--logger-no-color"); - args.add("--logger-color"); - args.add("--logger-lib=sc-log-test+6"); - args.add("--logger-lib=sc-log-test/6"); - args.add("--logger-lib=sc-log-test:6"); - args.add("--logger-lib=sc-log-test:verbose"); - args.add("--logger-lib=sc-log-test2+3"); - args.add("--logger-lib=sc-log-test"); - args.add("--logger-with-stupid-parameter=sdkfjsqdlkf"); + args.add("--log-level=999"); + args.add("--log-level=1"); + args.add("--log-no-color"); + args.add("--log-color"); + args.add("--log-lib=sc-log-test+6"); + args.add("--log-lib=sc-log-test/6"); + args.add("--log-lib=sc-log-test:6"); + args.add("--log-lib=sc-log-test:verbose"); + args.add("--log-lib=sc-log-test2+3"); + args.add("--log-lib=sc-log-test"); + args.add("--log-with-stupid-parameter=sdkfjsqdlkf"); args.add("--help"); - Logger.init(TestBasicLog.class.getCanonicalName(), args); + Logger.init(args); } @Test @Order(2) - public void secondInitialisation() { + public void bbSecondInitialisation() { List args = new ArrayList<>(); - Logger.init(TestBasicLog.class.getCanonicalName(), args); + Logger.init(args); } - + @Test @Order(3) - public void basicLogCall() { + public void ccBasicLogCall() { Log.print("Simple print"); Log.todo("Simple todo"); Log.error("Simple error"); @@ -90,8 +90,14 @@ public class TestBasicLog { @Test @Order(4) - public void testSimpleLog() { + public void ddTestSimpleLog() { testLog(); } + @Test + @Order(4) + public void eeUsage() { + Logger.usage(); + } + }