[DEV] update new init model
This commit is contained in:
parent
81f89c4667
commit
ed4e8e9fa8
@ -2,7 +2,6 @@ image: heeroyui/scenarium-gitlabci:latest
|
|||||||
|
|
||||||
variables:
|
variables:
|
||||||
JAVA_TOOL_OPTIONS: "-Dfile.encoding=UTF8"
|
JAVA_TOOL_OPTIONS: "-Dfile.encoding=UTF8"
|
||||||
#JAVA_HOME: "/usr/lib/jvm/java-14-openjdk/"
|
|
||||||
|
|
||||||
before_script:
|
before_script:
|
||||||
- which javac
|
- which javac
|
||||||
|
@ -53,61 +53,69 @@ public class Logger {
|
|||||||
private static boolean haveColor = false;
|
private static boolean haveColor = false;
|
||||||
private static boolean isInit = 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() {}
|
private Logger() {}
|
||||||
|
|
||||||
public static void usage(String applicationName) {
|
public static void usage() {
|
||||||
Log.print("logger - help : ");
|
Log.print(" [log]: Log session interface");
|
||||||
Log.print(" " + applicationName + " [options]");
|
Log.print(" --log-level= Change the default log level (set all Log level):");
|
||||||
Log.print(" --logger-level= Change the default log level (set all Log level):");
|
Log.print(" -3/none: debug None");
|
||||||
Log.print(" -3: debug None");
|
Log.print(" -2/print: debug Print");
|
||||||
Log.print(" -2: debug Print");
|
Log.print(" -1/todo: debug Todo");
|
||||||
Log.print(" -1: debug Todo");
|
Log.print(" 0/critical: debug Critical (default)");
|
||||||
Log.print(" 0: debug Critical (default)");
|
Log.print(" 1/error: debug Error");
|
||||||
Log.print(" 1: debug Error");
|
Log.print(" 2/warning: debug Warning");
|
||||||
Log.print(" 2: debug Warning");
|
Log.print(" 3/info: debug Info");
|
||||||
Log.print(" 3: debug Info (default in debug)");
|
Log.print(" 4/debug: debug Debug");
|
||||||
Log.print(" 4: debug Debug");
|
Log.print(" 5/verbose: debug Verbose");
|
||||||
Log.print(" 5: debug Verbose");
|
Log.print(" --log-lib=name:X Set a library specific level:");
|
||||||
Log.print(" --logger-lib=name:X Set a library specific level:");
|
Log.print(" name Name of the library");
|
||||||
Log.print(" name Name of the library");
|
Log.print(" X Log level to set [0..6]");
|
||||||
Log.print(" X Log level to set [0..6]");
|
Log.print(" !note!: ':' can be replace with '/' or '+'");
|
||||||
Log.print(" note: ':' can be replace with '/' or '+'");
|
Log.print(" --log-color Enable color in log");
|
||||||
Log.print(" --logger-color Enable color in log (default in Linux/debug)");
|
Log.print(" --log-no-color Disable color in log (default)");
|
||||||
Log.print(" --logger-no-color Disable color in log (default in Linux/release and Other)");
|
Log.print("");
|
||||||
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");
|
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
// private static void displayPackageDetails(final Package pkg)
|
* Initialize the library with generic argument in command line
|
||||||
// {
|
* @param args list of argument that are filtered after
|
||||||
// final String name = pkg.getName();
|
*/
|
||||||
// out.println(name);
|
public static void init(List<String> args) {
|
||||||
// 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<String> args) {
|
|
||||||
if (isInit)
|
if (isInit)
|
||||||
return;
|
return;
|
||||||
isInit = true;
|
isInit = true;
|
||||||
|
|
||||||
// displayPackageDetails(Package.getPackage("dustin.examples"));
|
|
||||||
|
|
||||||
for (int iii = 0; iii < args.size(); ++iii) {
|
for (int iii = 0; iii < args.size(); ++iii) {
|
||||||
String data = args.get(iii);
|
String data = args.get(iii);
|
||||||
if (data.startsWith("--logger-level=")) {
|
if (data.startsWith("--log-level=")) {
|
||||||
String value = data.substring(15);
|
String value = data.substring(12);
|
||||||
LogLevel level = LogLevel.fromString(value);
|
LogLevel level = LogLevel.fromString(value);
|
||||||
System.out.println("Change global level at " + value + " ==> " + level);
|
System.out.println("Change global level at " + value + " ==> " + level);
|
||||||
Logger.defaultLevel = level;
|
Logger.defaultLevel = level;
|
||||||
} else if (data.contentEquals("--logger-color"))
|
} else if (data.contentEquals("--log-color"))
|
||||||
Logger.haveColor = true;
|
Logger.haveColor = true;
|
||||||
else if (data.contentEquals("--logger-no-color"))
|
else if (data.contentEquals("--log-no-color"))
|
||||||
Logger.haveColor = false;
|
Logger.haveColor = false;
|
||||||
else if (data.startsWith("--logger-lib=")) {
|
else if (data.startsWith("--log-lib=")) {
|
||||||
String value = data.substring(13);
|
String value = data.substring(10);
|
||||||
String[] values = value.split("/");
|
String[] values = value.split("/");
|
||||||
if (values.length != 2) {
|
if (values.length != 2) {
|
||||||
values = value.split(":");
|
values = value.split(":");
|
||||||
@ -121,16 +129,13 @@ public class Logger {
|
|||||||
}
|
}
|
||||||
System.out.println("Change level of '" + values[0] + "' at " + LogLevel.fromString(values[1]));
|
System.out.println("Change level of '" + values[0] + "' at " + LogLevel.fromString(values[1]));
|
||||||
logLevels.put(values[0], 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.
|
// Clear all logger elements.
|
||||||
int iii = 0;
|
int iii = 0;
|
||||||
while (iii < args.size()) {
|
while (iii < args.size()) {
|
||||||
String data = args.get(iii);
|
String data = args.get(iii);
|
||||||
if (data.startsWith("--logger"))
|
if (data.startsWith("--log"))
|
||||||
args.remove(iii);
|
args.remove(iii);
|
||||||
else
|
else
|
||||||
iii++;
|
iii++;
|
||||||
|
@ -24,33 +24,33 @@ public class TestBasicLog {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Order(1)
|
@Order(1)
|
||||||
public void firstInitialisation() {
|
public void aaFirstInitialisation() {
|
||||||
List<String> args = new ArrayList<>();
|
List<String> args = new ArrayList<>();
|
||||||
args.add("--logger-level=999");
|
args.add("--log-level=999");
|
||||||
args.add("--logger-level=1");
|
args.add("--log-level=1");
|
||||||
args.add("--logger-no-color");
|
args.add("--log-no-color");
|
||||||
args.add("--logger-color");
|
args.add("--log-color");
|
||||||
args.add("--logger-lib=sc-log-test+6");
|
args.add("--log-lib=sc-log-test+6");
|
||||||
args.add("--logger-lib=sc-log-test/6");
|
args.add("--log-lib=sc-log-test/6");
|
||||||
args.add("--logger-lib=sc-log-test:6");
|
args.add("--log-lib=sc-log-test:6");
|
||||||
args.add("--logger-lib=sc-log-test:verbose");
|
args.add("--log-lib=sc-log-test:verbose");
|
||||||
args.add("--logger-lib=sc-log-test2+3");
|
args.add("--log-lib=sc-log-test2+3");
|
||||||
args.add("--logger-lib=sc-log-test");
|
args.add("--log-lib=sc-log-test");
|
||||||
args.add("--logger-with-stupid-parameter=sdkfjsqdlkf");
|
args.add("--log-with-stupid-parameter=sdkfjsqdlkf");
|
||||||
args.add("--help");
|
args.add("--help");
|
||||||
Logger.init(TestBasicLog.class.getCanonicalName(), args);
|
Logger.init(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Order(2)
|
@Order(2)
|
||||||
public void secondInitialisation() {
|
public void bbSecondInitialisation() {
|
||||||
List<String> args = new ArrayList<>();
|
List<String> args = new ArrayList<>();
|
||||||
Logger.init(TestBasicLog.class.getCanonicalName(), args);
|
Logger.init(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Order(3)
|
@Order(3)
|
||||||
public void basicLogCall() {
|
public void ccBasicLogCall() {
|
||||||
Log.print("Simple print");
|
Log.print("Simple print");
|
||||||
Log.todo("Simple todo");
|
Log.todo("Simple todo");
|
||||||
Log.error("Simple error");
|
Log.error("Simple error");
|
||||||
@ -90,8 +90,14 @@ public class TestBasicLog {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Order(4)
|
@Order(4)
|
||||||
public void testSimpleLog() {
|
public void ddTestSimpleLog() {
|
||||||
testLog();
|
testLog();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Order(4)
|
||||||
|
public void eeUsage() {
|
||||||
|
Logger.usage();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user