diff --git a/.classpath b/.classpath
index 183c41c..25741b0 100644
--- a/.classpath
+++ b/.classpath
@@ -1,16 +1,21 @@
-
+
-
-
+
-
+
+
+
+
+
+
+
@@ -18,5 +23,10 @@
-
+
+
+
+
+
+
diff --git a/.project b/.project
index 0536c47..9250819 100644
--- a/.project
+++ b/.project
@@ -16,8 +16,14 @@
+
+ org.eclipse.m2e.core.maven2Builder
+
+
+
+ org.eclipse.m2e.core.maven2Nature
org.eclipse.jdt.core.javanature
net.sf.eclipsecs.core.CheckstyleNature
diff --git a/doc/tutorial_01_create_library_logger.md b/doc/tutorial_01_create_library_logger.md
index 0c46ef1..240dc59 100644
--- a/doc/tutorial_01_create_library_logger.md
+++ b/doc/tutorial_01_create_library_logger.md
@@ -91,7 +91,7 @@ Generate some Logs:
```{.java}
final int plop = 51615;
Log.info("ma super ligne de Log " + plop);
-Log.error("a beautifull error);
+LOGGER.error("a beautifull error);
```
diff --git a/lutin_org-atriasoft-reggol.py b/lutin_org-atriasoft-reggol.py
index 8661b0b..9b26141 100644
--- a/lutin_org-atriasoft-reggol.py
+++ b/lutin_org-atriasoft-reggol.py
@@ -11,7 +11,7 @@ def get_type():
return "LIBRARY_DYNAMIC"
def get_desc():
- return "Scenarium reggol"
+ return "generic logger for java"
def get_licence():
return "MPL-2"
@@ -34,11 +34,12 @@ def configure(target, my_module):
'src/module-info.java',
'src/io/atriasoft/reggol/LogLevel.java',
'src/io/atriasoft/reggol/Logger.java',
- 'src/io/atriasoft/reggol/internal/Log.java',
+ 'src/io/atriasoft/reggol/LoggerFactory.java',
+ 'src/io/atriasoft/reggol/Reggol.java',
])
my_module.add_path('src/', type='java')
- my_module.add_flag('java', "RELEASE_15_PREVIEW");
+ my_module.add_flag('java', "RELEASE_19_PREVIEW");
return True
diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..d5d149a
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,101 @@
+
+ 4.0.0
+ org.atriasoft
+ reggol
+ 0.10.0
+
+ 3.11.0
+ 20
+ 20
+
+
+
+ gitea
+ https://gitea.atria-soft.org/api/packages/jatria-soft/maven
+
+
+
+
+ gitea
+ https://gitea.atria-soft.org/api/packages/jatria-soft/maven
+
+
+ gitea
+ https://gitea.atria-soft.org/api/packages/jatria-soft/maven
+
+
+
+
+ src
+ test/src
+ ${project.basedir}/out/maven/
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ ${maven.compiler.version}
+
+ ${maven.compiler.source}
+ ${maven.compiler.target}
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-source-plugin
+
+
+ attach-sources
+
+ jar
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+ 3.0.0-M5
+
+
+ maven-assembly-plugin
+
+
+
+ fully.qualified.MainClass
+
+
+
+ jar-with-dependencies
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-javadoc-plugin
+ 3.2.0
+
+ private
+ true
+
+
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-javadoc-plugin
+ 3.2.0
+
+ public
+
+
+
+
+
+
diff --git a/src/module-info.java b/src/module-info.java
index 954951a..e9f6dc1 100644
--- a/src/module-info.java
+++ b/src/module-info.java
@@ -1,6 +1,8 @@
-/** Basic module interface.
- *
- * @author Edouard DUPIN */
+/** @file
+ * @author Edouard DUPIN
+ * @copyright 2021, Edouard DUPIN, all right reserved
+ * @license MPL v2.0 (see license file)
+ */
open module org.atriasoft.reggol {
exports org.atriasoft.reggol;
diff --git a/src/org/atriasoft/reggol/LogLevel.java b/src/org/atriasoft/reggol/LogLevel.java
index 3185881..fad3f63 100644
--- a/src/org/atriasoft/reggol/LogLevel.java
+++ b/src/org/atriasoft/reggol/LogLevel.java
@@ -1,7 +1,12 @@
+/** @file
+ * @author Edouard DUPIN
+ * @copyright 2011, Edouard DUPIN, all right reserved
+ * @license MPL v2.0 (see license file)
+ */
package org.atriasoft.reggol;
public enum LogLevel {
- NONE(-3), PRINT(-2), TODO(-1), CRITICAL(0), ERROR(1), WARNING(2), INFO(3), DEBUG(4), VERBOSE(5);
+ NONE(0), PRINT(1), TODO(2), CRITICAL(3), ERROR(4), WARNING(5), INFO(6), DEBUG(7), VERBOSE(8);
public final int value;
diff --git a/src/org/atriasoft/reggol/Logger.java b/src/org/atriasoft/reggol/Logger.java
deleted file mode 100644
index 8018dd4..0000000
--- a/src/org/atriasoft/reggol/Logger.java
+++ /dev/null
@@ -1,488 +0,0 @@
-/*******************************************************************************
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at https://mozilla.org/MPL/2.0/.
- *
- * Contributors:
- * Revilloud Marc - initial API and implementation
- ******************************************************************************/
-package org.atriasoft.reggol;
-
-import java.nio.CharBuffer;
-import java.util.HashMap;
-import java.util.List;
-
-import org.atriasoft.reggol.internal.Log;
-
-@SuppressWarnings("unused")
-public class Logger {
- static class WrapInt {
- public int value;
-
- public WrapInt(final int val) {
- this.value = val;
- }
- }
-
- // background colors
- private static final String BASH_COLOR_BG_BLACK = "\033[40m";
-
- private static final String BASH_COLOR_BG_BLUE = "\033[44m";
-
- private static final String BASH_COLOR_BG_CYAN = "\033[46m";
- private static final String BASH_COLOR_BG_GREEN = "\033[42m";
- private static final String BASH_COLOR_BG_MAGENTA = "\033[45m";
- private static final String BASH_COLOR_BG_RED = "\033[41m";
- private static final String BASH_COLOR_BG_WHITE = "\033[47m";
- private static final String BASH_COLOR_BG_YELLOW = "\033[43m";
- // regular colors
- private static final String BASH_COLOR_BLACK = "\033[0;30m";
- private static final String BASH_COLOR_BLUE = "\033[0;34m";
- // emphasized (bolded) colors
- private static final String BASH_COLOR_BOLD_BLACK = "\033[1;30m";
- private static final String BASH_COLOR_BOLD_BLUE = "\033[1;34m";
- private static final String BASH_COLOR_BOLD_CYAN = "\033[1;36m";
- private static final String BASH_COLOR_BOLD_GREEN = "\033[1;32m";
- private static final String BASH_COLOR_BOLD_MAGENTA = "\033[1;35m";
- private static final String BASH_COLOR_BOLD_RED = "\033[1;31m";
- private static final String BASH_COLOR_BOLD_WHITE = "\033[1;37m";
- private static final String BASH_COLOR_BOLD_YELLOW = "\033[1;33m";
- private static final String BASH_COLOR_CYAN = "\033[0;36m";
- private static final String BASH_COLOR_GREEN = "\033[0;32m";
- private static final String BASH_COLOR_MAGENTA = "\033[0;35m";
- // Return to the normal color settings
- private static final String BASH_COLOR_NORMAL = "\033[0m";
- private static final String BASH_COLOR_RED = "\033[0;31m";
- private static final String BASH_COLOR_WHITE = "\033[0;37m";
- private static final String BASH_COLOR_YELLOW = "\033[0;33m";
- // go to the Top of bash
- private static final String BASH_GO_TOP = "\033[0;0f";
- static boolean criticalOccured = false;
-
- private static LogLevel defaultLevel = LogLevel.INFO;
- private static boolean haveClassName = false;
- // to enable color, you need to install in eclipse the plug-in "ANSI escape in console"
- private static boolean haveColor = true;
- private static boolean haveFileName = true;
- private static boolean haveLibName = true;
- private static boolean haveLineNumber = true;
- private static boolean haveThreadId = true;
- private static boolean haveThreadName = false;
- private static boolean isInit = false;
- private static HashMap logLevels = new HashMap<>();
- private static WrapInt sizeClassName = new WrapInt(25);
- private static WrapInt sizeFileName = new WrapInt(15);
- private static WrapInt sizeLibName = new WrapInt(0);
- private static WrapInt sizeLineNumber = new WrapInt(3);
- private static WrapInt sizeThreadId = new WrapInt(2);
- private static WrapInt sizeThreadName = new WrapInt(10);
- static {
- // Load system color state
- String value = System.getProperty("reggol.color");
- if (value != null) {
- if (value.contentEquals("true") || value.contentEquals("1")) {
- Logger.haveColor = true;
- } else if (value.contentEquals("false") || value.contentEquals("0")) {
- Logger.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("reggol.level");
- if (value != null) {
- final LogLevel level = LogLevel.fromString(value);
- System.out.println("Change global level at " + value + " ==> " + level);
- Logger.defaultLevel = level;
- }
- }
-
- private static String addGeneric(final String level, final String libName) {
- final StringBuilder out = new StringBuilder().append(level);
- out.append(Logger.printElement("", "", Logger.haveLibName, libName, Logger.sizeLibName));
- out.append(Logger.printElement(" | ", "", Logger.haveThreadId, Long.toString(Thread.currentThread().getId()), Logger.sizeThreadId));
- out.append(Logger.printElement(" | ", "", Logger.haveThreadName, Thread.currentThread().getName(), Logger.sizeThreadName));
- if (Logger.haveClassName || Logger.haveFileName || Logger.haveLineNumber) {
- final StackTraceElement callElem = Logger.getCallerElement();
- out.append(Logger.printElementLeft(" | l=", "", Logger.haveLineNumber, Long.toString(callElem.getLineNumber()), Logger.sizeLineNumber));
- out.append(Logger.printElement(" | ", "", Logger.haveClassName, callElem.getClassName(), Logger.sizeClassName));
- out.append(Logger.printElement(" | ", "", Logger.haveFileName, callElem.getFileName(), Logger.sizeFileName));
- }
- return out.toString();
- }
-
- /**
- * Replace all the values {} with the associated value in the parameters
- * @param data A generic string composed with "{}" element that will be replace.
- * @param values List of all element to add in the string.
- * @return a string with all the transformed data.
- */
- public static String concatenate(final String data, final Object... values) {
- final String[] cliped = data.split("\\{\\}");
- final StringBuilder out = new StringBuilder();
- final int nbElement = Math.max(values.length, cliped.length);
- for (int iii = 0; iii < nbElement; iii++) {
- if (iii < cliped.length) {
- out.append(cliped[iii]);
- } else {
- out.append(" ?? ");
- }
- if (iii < values.length) {
- if (values[iii] == null) {
- out.append("null");
- } else {
- out.append(values[iii].toString());
- }
- } else if (cliped.length - 1 != values.length) {
- out.append("{}");
- }
- }
- return out.toString();
- }
-
- public static void critical(final String libName, final String data) {
- criticalInternal(libName, data);
- }
-
- public static void critical(final String libName, final String data, final Object... values) {
- if (values.length == 0) {
- criticalInternal(libName, data);
- } else {
- critical(libName, concatenate(data, values));
- }
- }
-
- private static void criticalInternal(final String libName, final String data) {
- if (Logger.haveColor) {
- System.out.print(Logger.BASH_COLOR_BOLD_RED);
- }
- System.out.println(Logger.addGeneric("[C] ", libName) + " | " + data);
- if (Logger.haveColor) {
- System.out.print(Logger.BASH_COLOR_NORMAL);
- }
- System.out.flush();
- if (Logger.haveColor) {
- System.out.print(Logger.BASH_COLOR_YELLOW);
- }
- for (final StackTraceElement ste : Thread.currentThread().getStackTrace()) {
- System.out.println(ste);
- }
- System.out.print(Logger.BASH_COLOR_NORMAL);
- System.out.flush();
- Logger.criticalOccured = true;
- System.exit(-50);
- }
-
- public static void debug(final String libName, final String data) {
- debugInternal(libName, data);
- }
-
- public static void debug(final String libName, final String data, final Object... values) {
- if (values.length == 0) {
- debugInternal(libName, data);
- } else {
- debugInternal(libName, concatenate(data, values));
- }
- }
-
- public static void debugInternal(final String libName, final String data) {
- if (Logger.haveColor) {
- System.out.print(Logger.BASH_COLOR_YELLOW);
- }
- System.out.println(Logger.addGeneric("[D] ", libName) + " | " + data);
- if (Logger.haveColor) {
- System.out.print(Logger.BASH_COLOR_NORMAL);
- }
- }
-
- public static void displayBackTrace(final String libNameDraw) {
- final StackTraceElement[] list = Thread.currentThread().getStackTrace();
- Logger.error(libNameDraw, "Display Stacktrace :");
- for (int iii = 0; iii < list.length; iii++) {
- Logger.error(libNameDraw, " - " + list[iii]);
- }
- }
-
- public static void error(final String libName, final String data) {
- errorInternal(libName, data);
- }
-
- public static void error(final String libName, final String data, final Object... values) {
- if (values.length == 0) {
- errorInternal(libName, data);
- } else {
- errorInternal(libName, concatenate(data, values));
- }
- }
-
- private static void errorInternal(final String libName, final String data) {
- if (Logger.haveColor) {
- System.out.print(Logger.BASH_COLOR_RED);
- }
- System.out.println(Logger.addGeneric("[E] ", libName) + " | " + data);
- if (Logger.haveColor) {
- System.out.print(Logger.BASH_COLOR_NORMAL);
- }
- }
-
- private static StackTraceElement getCallerElement() {
- if (Thread.currentThread().getStackTrace().length > 6) {
- return Thread.currentThread().getStackTrace()[6];
- }
- if (Thread.currentThread().getStackTrace().length > 5) {
- return Thread.currentThread().getStackTrace()[5];
- }
- if (Thread.currentThread().getStackTrace().length > 4) {
- return Thread.currentThread().getStackTrace()[4];
- }
- if (Thread.currentThread().getStackTrace().length > 3) {
- return Thread.currentThread().getStackTrace()[3];
- }
- if (Thread.currentThread().getStackTrace().length > 2) {
- return Thread.currentThread().getStackTrace()[2];
- }
- if (Thread.currentThread().getStackTrace().length > 1) {
- return Thread.currentThread().getStackTrace()[1];
- }
- return Thread.currentThread().getStackTrace()[0];
- }
-
- /** This function permit to get the printable string to print in the log element (select here the number of char to print)
- * @param libName Name of the library
- * @return string to set in the reggol information */
- public static String getDrawableName(final String libName) {
- return libName; // String.format("%1$" + 15 + "s", libName);
- }
-
- public static boolean getNeedPrint(final String libName, final LogLevel level) {
- final LogLevel reference = Logger.logLevels.get(libName);
- if (reference == null) {
- return level.isLessEqual(Logger.defaultLevel);
- }
- return level.isLessEqual(reference);
- }
-
- public static void info(final String libName, final String data) {
- infoInternal(libName, data);
- }
-
- public static void info(final String libName, final String data, final Object... values) {
- if (values.length == 0) {
- infoInternal(libName, data);
- } else {
- infoInternal(libName, concatenate(data, values));
- }
- }
-
- private static void infoInternal(final String libName, final String data) {
- final StackTraceElement callElem = Logger.getCallerElement();
- if (Logger.haveColor) {
- System.out.print(Logger.BASH_COLOR_CYAN);
- }
- System.out.println(Logger.addGeneric("[I] ", libName) + " | " + data);
- if (Logger.haveColor) {
- System.out.print(Logger.BASH_COLOR_NORMAL);
- }
- }
-
- /** Initialize the library with generic argument in command line
- * @param args list of argument that are filtered after */
- public static void init(final List args) {
- if (Logger.isInit) {
- return;
- }
- Logger.isInit = true;
- for (int iii = 0; iii < args.size(); ++iii) {
- final String data = args.get(iii);
- if (data.startsWith("--log-level=")) {
- final String value = data.substring(12);
- final LogLevel level = LogLevel.fromString(value);
- System.out.println("Change global level at " + value + " ==> " + level);
- Logger.defaultLevel = level;
- } else if (data.contentEquals("--log-color")) {
- Logger.haveColor = true;
- } else if (data.contentEquals("--log-no-color")) {
- Logger.haveColor = false;
- } else if (data.startsWith("--log-lib=")) {
- final String value = data.substring(10);
- String[] values = value.split("/");
- if (values.length != 2) {
- values = value.split(":");
- if (values.length != 2) {
- values = value.split("\\+");
- if (values.length != 2) {
- System.err.println("Can not set the --reggol-lib= with value='" + value + "' not formated name:X or name/X or name+X");
- continue;
- }
- }
- }
- System.out.println("Change level of '" + values[0] + "' at " + LogLevel.fromString(values[1]));
- Logger.logLevels.put(values[0], LogLevel.fromString(values[1]));
- }
- }
- // Clear all reggol elements.
- int iii = 0;
- while (iii < args.size()) {
- final String data = args.get(iii);
- if (data.startsWith("--log")) {
- args.remove(iii);
- } else {
- iii++;
- }
- }
- }
-
- public static boolean isCriticalOccured() {
- return Logger.criticalOccured;
- }
-
- public static void print(final String libName, final String data) {
- System.out.println(data);
- //printInternal(libName, data);
- }
-
- public static void print(final String libName, final String data, final Object... values) {
- if (values.length == 0) {
- System.out.println(data);
- //printInternal(libName, data);
- } else {
- System.out.println(concatenate(data, values));
- //printInternal(libName, concatenate(data, values));
- }
- }
-
- private static String printElement(final String separator, final String separatorEnd, final boolean isActive, String data, final WrapInt size) {
- if (!isActive) {
- return "";
- }
- if (data == null) {
- data = "???";
- }
- final int stringSize = data.length();
- if (size.value < stringSize) {
- size.value = stringSize;
- }
- final int rest = size.value - stringSize;
- return separator + data + Logger.spaces(rest) + separatorEnd;
- }
-
- private static String printElementLeft(final String separator, final String separatorEnd, final boolean isActive, String data, final WrapInt size) {
- if (!isActive) {
- return "";
- }
- if (data == null) {
- data = "???";
- }
- final int stringSize = data.length();
- if (size.value < stringSize) {
- size.value = stringSize;
- }
- final int rest = size.value - stringSize;
- return separator + Logger.spaces(rest) + data + separatorEnd;
- }
-
- private static void printInternal(final String libName, final String data) {
- if (Logger.haveColor) {
- System.out.print(Logger.BASH_COLOR_WHITE);
- }
- System.out.println(Logger.addGeneric("[P] ", libName) + " | " + data);
- if (Logger.haveColor) {
- System.out.print(Logger.BASH_COLOR_NORMAL);
- }
- System.out.flush();
- }
-
- public static String spaces(final int spaces) {
- return CharBuffer.allocate(spaces).toString().replace('\0', ' ');
- }
-
- public static void todo(final String libName, final String data) {
- todoInternal(libName, data);
- }
-
- public static void todo(final String libName, final String data, final Object... values) {
- if (values.length == 0) {
- todoInternal(libName, data);
- } else {
- todoInternal(libName, concatenate(data, values));
- }
- }
-
- private static void todoInternal(final String libName, final String data) {
- if (Logger.haveColor) {
- System.out.print(Logger.BASH_COLOR_WHITE);
- }
- System.out.println(Logger.addGeneric("[TODO] ", libName) + " | " + data);
- if (Logger.haveColor) {
- System.out.print(Logger.BASH_COLOR_NORMAL);
- }
- }
-
- 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("");
- }
-
- public static void verbose(final String libName, final String data) {
- verboseInternal(libName, data);
- }
-
- public static void verbose(final String libName, final String data, final Object... values) {
- if (values.length == 0) {
- verboseInternal(libName, data);
- } else {
- verboseInternal(libName, concatenate(data, values));
- }
- }
-
- private static void verboseInternal(final String libName, final String data) {
- if (Logger.haveColor) {
- System.out.print(Logger.BASH_COLOR_WHITE);
- }
- System.out.println(Logger.addGeneric("[V] ", libName) + " | " + data);
- if (Logger.haveColor) {
- System.out.print(Logger.BASH_COLOR_NORMAL);
- }
- }
-
- public static void warning(final String libName, final String data) {
- warningInternal(libName, data);
- }
-
- public static void warning(final String libName, final String data, final Object... values) {
- if (values.length == 0) {
- warningInternal(libName, data);
- } else {
- warningInternal(libName, concatenate(data, values));
- }
- }
-
- private static void warningInternal(final String libName, final String data) {
- if (Logger.haveColor) {
- System.out.print(Logger.BASH_COLOR_MAGENTA);
- }
- System.out.println(Logger.addGeneric("[W] ", libName) + " | " + data);
- if (Logger.haveColor) {
- System.out.print(Logger.BASH_COLOR_NORMAL);
- }
- }
-
- private Logger() {}
-}
diff --git a/src/org/atriasoft/reggol/LoggerFactory.java b/src/org/atriasoft/reggol/LoggerFactory.java
new file mode 100644
index 0000000..67e70a3
--- /dev/null
+++ b/src/org/atriasoft/reggol/LoggerFactory.java
@@ -0,0 +1,31 @@
+/** @file
+ * @author Edouard DUPIN
+ * @copyright 2011, Edouard DUPIN, all right reserved
+ * @license MPL v2.0 (see license file)
+ */
+package org.atriasoft.reggol;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class LoggerFactory {
+ private List loggers = new ArrayList<>();
+ private static LoggerFactory factory = new LoggerFactory();
+
+ public static Logger getLogger(Class> clazz) {
+ return factory.get(clazz);
+ }
+
+ public Logger get(Class> clazz) {
+ for (Logger elem : this.loggers) {
+ if (elem.isForClass(clazz)) {
+ return elem;
+ }
+ }
+ Logger log = new Logger(clazz);
+ loggers.add(log);
+ return log;
+ }
+
+ private LoggerFactory() {}
+}
diff --git a/src/org/atriasoft/reggol/LoggerLocal.java b/src/org/atriasoft/reggol/LoggerLocal.java
deleted file mode 100644
index fd79059..0000000
--- a/src/org/atriasoft/reggol/LoggerLocal.java
+++ /dev/null
@@ -1,130 +0,0 @@
-package org.atriasoft.reggol;
-
-public class LoggerLocal {
- private final String className;
- private final String libraryName;
- private final String libraryNameDraw;
- private final boolean force;
- private final boolean printCritical;
- private final boolean printDebug;
- private final boolean printError;
- private final boolean printInfo;
- private final boolean printPrint;
- private final boolean printTodo;
- private final boolean printVerbose;
- private final boolean printWarning;
-
- public LoggerLocal(String libraryName, final Class> clazz) {
- this(libraryName, clazz, false);
- }
-
- public LoggerLocal(String libraryName, final Class> clazz, boolean force) {
- this.force = force;
- this.libraryName = libraryName;
- this.className = clazz.getCanonicalName();
- this.libraryNameDraw = Logger.getDrawableName(this.libraryName);
- this.printCritical = Logger.getNeedPrint(this.libraryName, LogLevel.CRITICAL);
- this.printDebug = Logger.getNeedPrint(this.libraryName, LogLevel.DEBUG);
- this.printError = Logger.getNeedPrint(this.libraryName, LogLevel.ERROR);
- this.printInfo = Logger.getNeedPrint(this.libraryName, LogLevel.INFO);
- this.printPrint = Logger.getNeedPrint(this.libraryName, LogLevel.PRINT);
- this.printTodo = Logger.getNeedPrint(this.libraryName, LogLevel.TODO);
- this.printVerbose = Logger.getNeedPrint(this.libraryName, LogLevel.VERBOSE);
- this.printWarning = Logger.getNeedPrint(this.libraryName, LogLevel.WARNING);
- }
-
- public void critical(final String data) {
- if (this.printCritical || this.force) {
- Logger.critical(this.libraryNameDraw, data);
- }
- }
-
- public void critical(final String data, Object... values) {
- if (this.printCritical || this.force) {
- Logger.critical(this.libraryNameDraw, data, values);
- }
- }
-
- public void debug(final String data) {
- if (this.printDebug || this.force) {
- Logger.debug(this.libraryNameDraw, data);
- }
- }
-
- public void debug(final String data, Object... values) {
- if (this.printDebug || this.force) {
- Logger.debug(this.libraryNameDraw, data, values);
- }
- }
-
- public void displayBackTrace() {
- // TODO Auto-generated method stub
- }
-
- public void error(final String data) {
- if (this.printError || this.force) {
- Logger.error(this.libraryNameDraw, data);
- }
- }
-
- public void error(final String data, Object... values) {
- if (this.printError || this.force) {
- Logger.error(this.libraryNameDraw, data, values);
- }
- }
-
- public void info(final String data) {
- if (this.printInfo || this.force) {
- Logger.info(this.libraryNameDraw, data);
- }
- }
-
- public void info(final String data, Object... values) {
- if (this.printInfo || this.force) {
- Logger.info(this.libraryNameDraw, data, values);
- }
- }
-
- public void print(final String data) {
- if (this.printPrint || this.force) {
- Logger.print(this.libraryNameDraw, data);
- }
- }
-
- public void print(final String data, Object... values) {
- if (this.printPrint || this.force) {
- Logger.print(this.libraryNameDraw, data, values);
- }
- }
-
- public void todo(final String data) {
- if (this.printTodo || this.force) {
- Logger.todo(this.libraryNameDraw, data);
- }
- }
-
- public void todo(final String data, Object... values) {
- if (this.printTodo || this.force) {
- Logger.todo(this.libraryNameDraw, data, values);
- }
- }
-
- public void verbose(final String data) {
- if (this.printVerbose || this.force) {
- Logger.verbose(this.libraryNameDraw, data);
- }
- }
-
- public void warning(final String data) {
- if (this.printWarning || this.force) {
- Logger.warning(this.libraryNameDraw, data);
- }
- }
-
- public void warning(final String data, Object... values) {
- if (this.printWarning || this.force) {
- Logger.warning(this.libraryNameDraw, data, values);
- }
- }
-
-}
diff --git a/src/org/atriasoft/reggol/Reggol.java b/src/org/atriasoft/reggol/Reggol.java
new file mode 100644
index 0000000..6d74116
--- /dev/null
+++ b/src/org/atriasoft/reggol/Reggol.java
@@ -0,0 +1,370 @@
+/** @file
+ * @author Edouard DUPIN
+ * @copyright 2011, Edouard DUPIN, all right reserved
+ * @license MPL v2.0 (see license file)
+ */
+package org.atriasoft.reggol;
+
+import java.nio.CharBuffer;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.regex.Pattern;
+
+@SuppressWarnings("unused")
+public class Reggol {
+ record Levels(String regex, LogLevel level) {};
+
+ static class WrapInt {
+ public int value;
+
+ public WrapInt(final int val) {
+ this.value = val;
+ }
+ }
+
+ // background colors
+ private static final String BASH_COLOR_BG_BLACK = "\033[40m";
+
+ private static final String BASH_COLOR_BG_BLUE = "\033[44m";
+
+ private static final String BASH_COLOR_BG_CYAN = "\033[46m";
+ private static final String BASH_COLOR_BG_GREEN = "\033[42m";
+ private static final String BASH_COLOR_BG_MAGENTA = "\033[45m";
+ private static final String BASH_COLOR_BG_RED = "\033[41m";
+ private static final String BASH_COLOR_BG_WHITE = "\033[47m";
+ private static final String BASH_COLOR_BG_YELLOW = "\033[43m";
+ // regular colors
+ private static final String BASH_COLOR_BLACK = "\033[0;30m";
+ private static final String BASH_COLOR_BLUE = "\033[0;34m";
+ // emphasized (bold) colors
+ private static final String BASH_COLOR_BOLD_BLACK = "\033[1;30m";
+ private static final String BASH_COLOR_BOLD_BLUE = "\033[1;34m";
+ private static final String BASH_COLOR_BOLD_CYAN = "\033[1;36m";
+ private static final String BASH_COLOR_BOLD_GREEN = "\033[1;32m";
+ private static final String BASH_COLOR_BOLD_MAGENTA = "\033[1;35m";
+ private static final String BASH_COLOR_BOLD_RED = "\033[1;31m";
+ private static final String BASH_COLOR_BOLD_WHITE = "\033[1;37m";
+ private static final String BASH_COLOR_BOLD_YELLOW = "\033[1;33m";
+ private static final String BASH_COLOR_CYAN = "\033[0;36m";
+ private static final String BASH_COLOR_GREEN = "\033[0;32m";
+ private static final String BASH_COLOR_MAGENTA = "\033[0;35m";
+ // Return to the normal color settings
+ private static final String BASH_COLOR_NORMAL = "\033[0m";
+ private static final String BASH_COLOR_RED = "\033[0;31m";
+ private static final String BASH_COLOR_WHITE = "\033[0;37m";
+ private static final String BASH_COLOR_YELLOW = "\033[0;33m";
+ // go to the Top of bash
+ private static final String BASH_GO_TOP = "\033[0;0f";
+ static String[] colorsLevels = {
+ BASH_COLOR_BLACK, // NONE
+ BASH_COLOR_BLACK, // PRINT
+ BASH_COLOR_BOLD_YELLOW, // TODO
+ BASH_COLOR_BOLD_MAGENTA, // CRITICAL
+ BASH_COLOR_BOLD_RED, // ERROR
+ BASH_COLOR_BOLD_MAGENTA, // WARNING,
+ BASH_COLOR_BLACK, // INFO
+ BASH_COLOR_BG_GREEN, // DEBUG
+ BASH_COLOR_BG_CYAN // VERBOSE
+ };
+ static String[] modelLevels = {
+ "[-] ", // NONE
+ "[P] ", // PRINT
+ "[TODO] ", // TODO
+ "[C] ", // CRITICAL
+ "[E] ", // ERROR
+ "[W] ", // WARNING,
+ "[I] ", // INFO
+ "[D] ", // DEBUG
+ "[V] " // VERBOSE
+ };
+ static boolean criticalOccured = false;
+
+ private static LogLevel defaultLevel = LogLevel.INFO;
+ private static boolean haveClassName = false;
+ // to enable color, you need to install in eclipse the plug-in "ANSI escape in console"
+ private static boolean haveColor = true;
+ private static boolean haveFileName = true;
+ private static boolean haveLibName = true;
+ private static boolean haveLineNumber = true;
+ private static boolean haveThreadId = true;
+ private static boolean haveThreadName = false;
+ private static boolean isInit = false;
+ private static List logLevels = new ArrayList<>();
+ private static WrapInt sizeClassName = new WrapInt(25);
+ private static WrapInt sizeFileName = new WrapInt(15);
+ private static WrapInt sizeLibName = new WrapInt(0);
+ private static WrapInt sizeLineNumber = new WrapInt(3);
+ private static WrapInt sizeThreadId = new WrapInt(2);
+ private static WrapInt sizeThreadName = new WrapInt(10);
+ private static boolean dryRun = false;
+ static {
+ // Load system color state
+ String value = System.getProperty("reggol.color");
+ if (value != null) {
+ if (value.contentEquals("true") || value.contentEquals("1")) {
+ Reggol.haveColor = true;
+ } else if (value.contentEquals("false") || value.contentEquals("0")) {
+ Reggol.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("reggol.level");
+ if (value != null) {
+ final LogLevel level = LogLevel.fromString(value);
+ System.out.println("Change global level at " + value + " ==> " + level);
+ Reggol.defaultLevel = level;
+ }
+ }
+
+ private static void addGeneric(final StringBuilder out, final String level, final String pkg, final String classCanonicalName) {
+ out.append(level);
+ if (Reggol.haveFileName && Reggol.haveLineNumber) {
+ String[] ploppp = pkg.split("\\.");
+ Reggol.printElement(out, "", "", Reggol.haveLibName, ploppp[ploppp.length-1], Reggol.sizeLibName);
+ } else {
+ Reggol.printElement(out, "", "", Reggol.haveLibName, pkg, Reggol.sizeLibName);
+ }
+ Reggol.printElement(out, " | ", "", Reggol.haveThreadId, Long.toString(Thread.currentThread().getId()), Reggol.sizeThreadId);
+ Reggol.printElement(out, " | ", "", Reggol.haveThreadName, Thread.currentThread().getName(), Reggol.sizeThreadName);
+ if (Reggol.haveFileName || Reggol.haveLineNumber) {
+
+ }
+ if (Reggol.haveClassName || Reggol.haveFileName || Reggol.haveLineNumber) {
+ final StackTraceElement callElem = Reggol.getCallerElement();
+ Reggol.printElement(out, " | ", "", Reggol.haveClassName, callElem.getClassName(), Reggol.sizeClassName);
+ if (Reggol.haveFileName && Reggol.haveLineNumber) {
+ Reggol.printElementLeft(out, " | ", "", true, pkg + "..(" + callElem.getFileName() + ":" + Long.toString(callElem.getLineNumber()) + ")", Reggol.sizeLineNumber);
+ } else {
+ Reggol.printElementLeft(out, " | l=", "", Reggol.haveLineNumber, Long.toString(callElem.getLineNumber()), Reggol.sizeLineNumber);
+ Reggol.printElement(out, " | ", "", Reggol.haveFileName, callElem.getFileName(), Reggol.sizeFileName);
+ }
+ }
+ }
+
+ /**
+ * Replace all the values {} with the associated value in the parameters
+ * @param data A generic string composed with "{}" element that will be replace.
+ * @param values List of all element to add in the string.
+ * @return a string with all the transformed data.
+ */
+ public static void concatenate(final StringBuilder out, final String data, final Object... values) {
+ final String[] cliped = data.split("\\{\\}");
+ final int nbElement = Math.max(values.length, cliped.length);
+ for (int iii = 0; iii < nbElement; iii++) {
+ if (iii < cliped.length) {
+ out.append(cliped[iii]);
+ } else {
+ out.append(" ?? ");
+ }
+ if (iii < values.length) {
+ if (values[iii] == null) {
+ out.append("null");
+ } else {
+ out.append(values[iii].toString());
+ }
+ } else if (cliped.length - 1 != values.length) {
+ out.append("{}");
+ }
+ }
+ }
+
+ private static StackTraceElement getCallerElement() {
+ StackTraceElement[] traces = Thread.currentThread().getStackTrace();
+ if (traces.length > 5) {
+ return traces[5];
+ }
+ if (traces.length > 4) {
+ return traces[4];
+ }
+ if (traces.length > 3) {
+ return traces[3];
+ }
+ if (traces.length > 2) {
+ return traces[2];
+ }
+ if (traces.length > 1) {
+ return traces[1];
+ }
+ return traces[0];
+ }
+
+ /** Initialize the library with generic argument in command line
+ * @param args list of argument that are filtered after */
+ public static void init(final List args) {
+ if (Reggol.isInit) {
+ return;
+ }
+ Reggol.isInit = true;
+ for (int iii = 0; iii < args.size(); ++iii) {
+ final String data = args.get(iii);
+ if (data.startsWith("--log-level=")) {
+ final String value = data.substring(12);
+ final LogLevel level = LogLevel.fromString(value);
+ System.out.println("Change global level at " + value + " ==> " + level);
+ Reggol.defaultLevel = level;
+ } else if (data.contentEquals("--log-color")) {
+ Reggol.haveColor = true;
+ } else if (data.contentEquals("--log-no-color")) {
+ Reggol.haveColor = false;
+ } else if (data.startsWith("--log-lib=")) {
+ final String value = data.substring(10);
+ String[] values = value.split("/");
+ if (values.length != 2) {
+ values = value.split(":");
+ if (values.length != 2) {
+ values = value.split("\\+");
+ if (values.length != 2) {
+ System.err.println("Can not set the --reggol-lib= with value='" + value + "' not formated name:X or name/X or name+X");
+ continue;
+ }
+ }
+ }
+ System.out.println("Change level of '" + values[0] + "' at " + LogLevel.fromString(values[1]));
+ Reggol.logLevels.add(new Levels(values[0], LogLevel.fromString(values[1])));
+ }
+ }
+ // Clear all reggol elements.
+ int iii = 0;
+ while (iii < args.size()) {
+ final String data = args.get(iii);
+ if (data.startsWith("--log")) {
+ args.remove(iii);
+ } else {
+ iii++;
+ }
+ }
+ }
+
+ public static boolean isCriticalOccured() {
+ return Reggol.criticalOccured;
+ }
+
+
+ private static void printElement(final StringBuilder out, final String separator, final String separatorEnd, final boolean isActive, String data, final WrapInt size) {
+ if (!isActive) {
+ return;
+ }
+ if (data == null) {
+ data = "???";
+ }
+ final int stringSize = data.length();
+ if (size.value < stringSize) {
+ size.value = stringSize;
+ }
+ final int rest = size.value - stringSize;
+ out.append(separator);
+ out.append(data);
+ out.append(Reggol.spaces(rest));
+ out.append(separatorEnd);
+ }
+
+ private static void printElementLeft(final StringBuilder out, final String separator, final String separatorEnd, final boolean isActive, String data, final WrapInt size) {
+ if (!isActive) {
+ return;
+ }
+ if (data == null) {
+ data = "???";
+ }
+ final int stringSize = data.length();
+ if (size.value < stringSize) {
+ size.value = stringSize;
+ }
+ final int rest = size.value - stringSize;
+ out.append(separator);
+ out.append(Reggol.spaces(rest));
+ out.append(data);
+ out.append(separatorEnd);
+ }
+
+
+ public static String spaces(final int spaces) {
+ return CharBuffer.allocate(spaces).toString().replace('\0', ' ');
+ }
+
+
+ public static void usage() {
+ System.out.println(" [log]: Log session interface");
+ System.out.println(" --log-level= Change the default log level (set all Log level):");
+ System.out.println(" -3/none: debug None");
+ System.out.println(" -2/print: debug Print");
+ System.out.println(" -1/todo: debug Todo");
+ System.out.println(" 0/critical: debug Critical (default)");
+ System.out.println(" 1/error: debug Error");
+ System.out.println(" 2/warning: debug Warning");
+ System.out.println(" 3/info: debug Info");
+ System.out.println(" 4/debug: debug Debug");
+ System.out.println(" 5/verbose: debug Verbose");
+ System.out.println(" --log-lib=name:X Set a library specific level:");
+ System.out.println(" name Name of the library");
+ System.out.println(" X Log level to set [0..6]");
+ System.out.println(" !note!: ':' can be replace with '/' or '+'");
+ System.out.println(" --log-color Enable color in log");
+ System.out.println(" --log-no-color Disable color in log (default)");
+ System.out.println("");
+ }
+ /**
+ * Generic method to render a log with the color and all the needed displays
+ * @param level
+ * @param pkg
+ * @param classCanonicalName
+ * @param model
+ * @param values
+ */
+ public static void genericLog(final LogLevel level, final String pkg, final String classCanonicalName, final String model, final Object... values) {
+ final StringBuilder toPrint = new StringBuilder(4096);
+ if (Reggol.haveColor) {
+ toPrint.append(colorsLevels[level.value]);
+ }
+ Reggol.addGeneric(toPrint, modelLevels[level.value], pkg, classCanonicalName);
+ toPrint.append( " | " );
+ if (values.length != 0) {
+ concatenate(toPrint, model, values);
+ } else {
+ toPrint.append(model);
+ }
+ toPrint.append("\n");
+ if (level == LogLevel.CRITICAL) {
+ if (Reggol.haveColor) {
+ toPrint.append(Reggol.BASH_COLOR_YELLOW);
+ }
+ for (final StackTraceElement ste : Thread.currentThread().getStackTrace()) {
+ toPrint.append(ste);
+ toPrint.append("\n");
+ }
+ toPrint.append(Reggol.BASH_COLOR_NORMAL);
+ System.out.print(toPrint.toString());
+ System.out.flush();
+ Reggol.criticalOccured = true;
+ System.exit(-50);
+ }
+ if (Reggol.haveColor) {
+ toPrint.append(Reggol.BASH_COLOR_NORMAL);
+ }
+ if (dryRun == false) {
+ System.out.print(toPrint.toString());
+ if (level == LogLevel.PRINT) {
+ System.out.flush();
+ }
+ }
+ }
+
+ private Reggol() {}
+
+ public static LogLevel getLevelPrint(String name) {
+ for (Levels elem : Reggol.logLevels) {
+ if (Pattern.matches(elem.regex(), name)) {
+ return elem.level();
+ }
+ }
+ return defaultLevel;
+ }
+
+ public static void dryRun(boolean dryRunMode) {
+ dryRun = dryRunMode;
+
+ }
+}
diff --git a/src/org/atriasoft/reggol/internal/Log.java b/src/org/atriasoft/reggol/internal/Log.java
deleted file mode 100644
index bf6ca7f..0000000
--- a/src/org/atriasoft/reggol/internal/Log.java
+++ /dev/null
@@ -1,60 +0,0 @@
-package org.atriasoft.reggol.internal;
-
-import org.atriasoft.reggol.LogLevel;
-import org.atriasoft.reggol.Logger;
-
-public class Log {
- private static final String LIB_NAME = "reggol";
- private static final String LIB_NAME_DRAW = Logger.getDrawableName(LIB_NAME);
- private static final boolean PRINT_CRITICAL = Logger.getNeedPrint(LIB_NAME, LogLevel.CRITICAL);
- private static final boolean PRINT_ERROR = Logger.getNeedPrint(LIB_NAME, LogLevel.ERROR);
- private static final boolean PRINT_WARNING = Logger.getNeedPrint(LIB_NAME, LogLevel.WARNING);
- private static final boolean PRINT_INFO = Logger.getNeedPrint(LIB_NAME, LogLevel.INFO);
- private static final boolean PRINT_DEBUG = Logger.getNeedPrint(LIB_NAME, LogLevel.DEBUG);
- private static final boolean PRINT_VERBOSE = Logger.getNeedPrint(LIB_NAME, LogLevel.VERBOSE);
- private static final boolean PRINT_TODO = Logger.getNeedPrint(LIB_NAME, LogLevel.TODO);
- private static final boolean PRINT_PRINT = Logger.getNeedPrint(LIB_NAME, LogLevel.PRINT);
-
- private Log() {}
-
- public static void print(String data) {
- if (PRINT_PRINT)
- Logger.print(LIB_NAME_DRAW, data);
- }
-
- public static void todo(String data) {
- if (PRINT_TODO)
- Logger.todo(LIB_NAME_DRAW, data);
- }
-
- public static void critical(String data) {
- if (PRINT_CRITICAL)
- Logger.critical(LIB_NAME_DRAW, data);
- }
-
- public static void error(String data) {
- if (PRINT_ERROR)
- Logger.error(LIB_NAME_DRAW, data);
- }
-
- public static void warning(String data) {
- if (PRINT_WARNING)
- Logger.warning(LIB_NAME_DRAW, data);
- }
-
- public static void info(String data) {
- if (PRINT_INFO)
- Logger.info(LIB_NAME_DRAW, data);
- }
-
- public static void debug(String data) {
- if (PRINT_DEBUG)
- Logger.debug(LIB_NAME_DRAW, data);
- }
-
- public static void verbose(String data) {
- if (PRINT_VERBOSE)
- Logger.verbose(LIB_NAME_DRAW, data);
- }
-
-}
diff --git a/test/src/test/atriasoft/reggol/Log.java b/test/src/test/atriasoft/reggol/Log.java
deleted file mode 100644
index 76192d2..0000000
--- a/test/src/test/atriasoft/reggol/Log.java
+++ /dev/null
@@ -1,59 +0,0 @@
-package test.atriasoft.reggol;
-
-import org.atriasoft.reggol.LogLevel;
-import org.atriasoft.reggol.Logger;
-
-public class Log {
- private static final String LIB_NAME = "sc-log-test";
- private static final String LIB_NAME_DRAW = Logger.getDrawableName(LIB_NAME);
- private static final boolean PRINT_CRITICAL = Logger.getNeedPrint(LIB_NAME, LogLevel.CRITICAL);
- private static final boolean PRINT_ERROR = Logger.getNeedPrint(LIB_NAME, LogLevel.ERROR);
- private static final boolean PRINT_WARNING = Logger.getNeedPrint(LIB_NAME, LogLevel.WARNING);
- private static final boolean PRINT_INFO = Logger.getNeedPrint(LIB_NAME, LogLevel.INFO);
- private static final boolean PRINT_DEBUG = Logger.getNeedPrint(LIB_NAME, LogLevel.DEBUG);
- private static final boolean PRINT_VERBOSE = Logger.getNeedPrint(LIB_NAME, LogLevel.VERBOSE);
- private static final boolean PRINT_TODO = Logger.getNeedPrint(LIB_NAME, LogLevel.TODO);
- private static final boolean PRINT_PRINT = Logger.getNeedPrint(LIB_NAME, LogLevel.PRINT);
-
- private Log() {}
-
- public static void print(String data) {
- if (PRINT_PRINT)
- Logger.print(LIB_NAME_DRAW, data);
- }
-
- public static void critical(String data) {
- if (PRINT_CRITICAL)
- Logger.critical(LIB_NAME_DRAW, data);
- }
-
- public static void error(String data) {
- if (PRINT_ERROR)
- Logger.error(LIB_NAME_DRAW, data);
- }
-
- public static void warning(String data) {
- if (PRINT_WARNING)
- Logger.warning(LIB_NAME_DRAW, data);
- }
-
- public static void info(String data) {
- if (PRINT_INFO)
- Logger.info(LIB_NAME_DRAW, data);
- }
-
- public static void debug(String data) {
- if (PRINT_DEBUG)
- Logger.debug(LIB_NAME_DRAW, data);
- }
-
- public static void verbose(String data) {
- if (PRINT_VERBOSE)
- Logger.verbose(LIB_NAME_DRAW, data);
- }
-
- public static void todo(String data) {
- if (PRINT_TODO)
- Logger.todo(LIB_NAME_DRAW, data);
- }
-}
diff --git a/test/src/test/atriasoft/reggol/Log2.java b/test/src/test/atriasoft/reggol/Log2.java
deleted file mode 100644
index 74cf75f..0000000
--- a/test/src/test/atriasoft/reggol/Log2.java
+++ /dev/null
@@ -1,18 +0,0 @@
-package test.atriasoft.reggol;
-
-import org.atriasoft.reggol.LogLevel;
-import org.atriasoft.reggol.Logger;
-
-public class Log2 {
- private static final String LIB_NAME = "sc-log-test-2";
- private static final String LIB_NAME_DRAW = Logger.getDrawableName(LIB_NAME);
- private static final boolean PRINT_DEBUG = Logger.getNeedPrint(LIB_NAME, LogLevel.DEBUG);
-
- private Log2() {}
-
- public static void debug(String data) {
- if (PRINT_DEBUG)
- Logger.debug(LIB_NAME_DRAW, data);
- }
-
-}
diff --git a/test/src/test/atriasoft/reggol/TestBasicLog.java b/test/src/test/atriasoft/reggol/TestBasicLog.java
index ea09931..bb445c0 100644
--- a/test/src/test/atriasoft/reggol/TestBasicLog.java
+++ b/test/src/test/atriasoft/reggol/TestBasicLog.java
@@ -1,17 +1,16 @@
-/*******************************************************************************
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at https://mozilla.org/MPL/2.0/.
- *
- * Contributors:
- * Revilloud Marc - initial API and implementation
- ******************************************************************************/
+/** @file
+ * @author Edouard DUPIN
+ * @copyright 2011, Edouard DUPIN, all right reserved
+ * @license MPL v2.0 (see license file)
+ */
package test.atriasoft.reggol;
import java.util.ArrayList;
import java.util.List;
import org.atriasoft.reggol.Logger;
+import org.atriasoft.reggol.LoggerFactory;
+import org.atriasoft.reggol.Reggol;
import org.junit.jupiter.api.MethodOrderer.OrderAnnotation;
import org.junit.jupiter.api.Order;
@@ -20,6 +19,11 @@ import org.junit.jupiter.api.TestMethodOrder;
@TestMethodOrder(OrderAnnotation.class)
public class TestBasicLog {
+ private static Logger LOGGER = LoggerFactory.getLogger(TestBasicLog.class);
+
+ class Class2 {
+
+ }
@Test
@Order(1)
@@ -29,74 +33,40 @@ public class TestBasicLog {
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-lib=test.atriasoft.realog+6");
+ args.add("--log-lib=test.atriasoft.realog/6");
+ args.add("--log-lib=test.atriasoft.realog:6");
+ args.add("--log-lib=test.atriasoft.realog:verbose");
+ args.add("--log-lib=test.atriasoft.realog2+3");
+ args.add("--log-lib=test.atriasoft.realog");
args.add("--log-with-stupid-parameter=sdkfjsqdlkf");
args.add("--help");
- Logger.init(args);
+ Reggol.init(args);
}
@Test
@Order(2)
public void bbSecondInitialisation() {
List args = new ArrayList<>();
- Logger.init(args);
+ Reggol.init(args);
}
@Test
@Order(3)
public void ccBasicLogCall() {
- Log.print("Simple print");
- Log.todo("Simple todo");
- Log.error("Simple error");
- Log.warning("Simple warning");
- Log.info("Simple info");
- Log.debug("Simple debug");
- Log.verbose("Simple verbose");
- }
-
- // TODO REFACTO REMOVE this and set it in the Test of the reggol.
- public static String getAAAAAAA(int dfsdf) {
- int hhh = 0;
- for (int kkk = 0; kkk < dfsdf; kkk++)
- for (int iii = 0; iii < 10000; iii++)
- for (int jjj = 0; jjj < 100000; jjj++)
- for (int lll = 0; lll < 100000; lll++)
- hhh++;
- return "kkk" + hhh;
- }
-
- public static void testLog() {
- Log.print("test direct [START]");
- // test de 10 secondes contre 0.0?? second quand le niveau n'est pas assez grand ...
- long timeStart = System.currentTimeMillis();
- for (int iii = 0; iii < 100000000; iii++)
- Log2.debug("test direct");
- long timeStop = System.currentTimeMillis();
- Log.print("test direct [END] : " + timeStart + " to " + timeStop + " ==> delta=" + (timeStop - timeStart));
- Log.print("test concat [START]");
- // C'est très long dans les 2 cas ...
- timeStart = System.currentTimeMillis();
- for (int iii = 0; iii < 6; iii++)
- Log2.debug("test concat: non fonctionnel, il applelle le get a chaque log ... " + getAAAAAAA(iii));
- timeStop = System.currentTimeMillis();
- Log.print("test concat [END] : " + timeStart + " to " + timeStop + " ==> delta=" + (timeStop - timeStart));
- }
-
- @Test
- @Order(4)
- public void ddTestSimpleLog() {
- testLog();
+ LOGGER.print("Simple print");
+ LOGGER.todo("Simple todo");
+ LOGGER.error("Simple error");
+ LOGGER.warning("Simple warning");
+ LOGGER.info("Simple info");
+ LOGGER.debug("Simple debug");
+ LOGGER.verbose("Simple verbose");
}
@Test
@Order(4)
public void eeUsage() {
- Logger.usage();
+ Reggol.usage();
}
}
diff --git a/test/src/test/atriasoft/reggol/TestReggolPerformance.java b/test/src/test/atriasoft/reggol/TestReggolPerformance.java
new file mode 100644
index 0000000..ac5bad4
--- /dev/null
+++ b/test/src/test/atriasoft/reggol/TestReggolPerformance.java
@@ -0,0 +1,78 @@
+/** @file
+ * @author Edouard DUPIN
+ * @copyright 2011, Edouard DUPIN, all right reserved
+ * @license MPL v2.0 (see license file)
+ */
+package test.atriasoft.reggol;
+
+import org.atriasoft.reggol.LogLevel;
+import org.atriasoft.reggol.Logger;
+import org.atriasoft.reggol.LoggerFactory;
+import org.atriasoft.reggol.Reggol;
+
+import org.junit.jupiter.api.MethodOrderer.OrderAnnotation;
+import org.junit.jupiter.api.Order;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestMethodOrder;
+
+@TestMethodOrder(OrderAnnotation.class)
+public class TestReggolPerformance {
+ private static Logger LOGGER = LoggerFactory.getLogger(TestReggolPerformance.class);
+ private static int MAX_COUNT = 10000;
+
+ class Class2 {
+
+ }
+
+ @Test
+ @Order(1)
+ public void LocalConcatLog() {
+ Logger LOGGER2 = LoggerFactory.getLogger(Class2.class);
+ LOGGER2.setLevel(LogLevel.DEBUG);
+ Reggol.dryRun(true);
+ long timeStart = System.currentTimeMillis();
+ for (int iii = 0; iii < MAX_COUNT; iii++)
+ LOGGER2.debug(iii + " test direct" + "lkjlkj" + " sef " + iii*2 + " qsdfgqs");
+ long timeStop = System.currentTimeMillis();
+ Reggol.dryRun(false);
+ LOGGER.print("User concat and dry print. delta=" + (double)(timeStop - timeStart)/MAX_COUNT*1000 + " ms");
+ }
+ @Test
+ @Order(2)
+ public void LocalConcatNoLog() {
+ Logger LOGGER2 = LoggerFactory.getLogger(Class2.class);
+ LOGGER2.setLevel(LogLevel.CRITICAL);
+ long timeStart = System.currentTimeMillis();
+ for (int iii = 0; iii < MAX_COUNT; iii++)
+ LOGGER2.debug(iii + " test direct" + "lkjlkj" + " sef " + iii*2 + " qsdfgqs");
+ long timeStop = System.currentTimeMillis();
+ LOGGER.print("User concat and no Log. delta=" + (double)(timeStop - timeStart)/MAX_COUNT*1000 + " ms");
+ }
+
+ @Test
+ @Order(3)
+ public void noConcatNoLog() {
+ Logger LOGGER2 = LoggerFactory.getLogger(Class2.class);
+ LOGGER2.setLevel(LogLevel.VERBOSE);
+ Reggol.dryRun(true);
+ long timeStart = System.currentTimeMillis();
+ for (int iii = 0; iii < MAX_COUNT; iii++)
+ LOGGER2.debug("{} test direct {} sef {} qsdfgqs", iii, "lkjlkj", iii*2);
+ long timeStop = System.currentTimeMillis();
+ Reggol.dryRun(false);
+ LOGGER.print("logger concat and dry print. delta=" + (double)(timeStop - timeStart)/MAX_COUNT*1000 + " ms");
+ }
+ @Test
+ @Order(4)
+ public void noConcatLog() {
+ Logger LOGGER2 = LoggerFactory.getLogger(Class2.class);
+ LOGGER2.setLevel(LogLevel.CRITICAL);
+ long timeStart = System.currentTimeMillis();
+ for (int iii = 0; iii < MAX_COUNT; iii++)
+ LOGGER2.debug("{} test direct {} sef {} qsdfgqs", iii, "lkjlkj", iii*2);
+ long timeStop = System.currentTimeMillis();
+ LOGGER.print("Logger concat and no Log. delta=" + (double)(timeStop - timeStart)/MAX_COUNT*1000 + " ms");
+ }
+
+
+}
diff --git a/version.txt b/version.txt
index c70836c..29b2d3e 100644
--- a/version.txt
+++ b/version.txt
@@ -1 +1 @@
-0.9.0-dev
+0.10.0-dev