[DEV] add color in the logs
This commit is contained in:
parent
c0b5a3bc96
commit
59e2c3a845
@ -10,50 +10,122 @@ package io.scenarium.logger;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class Logger {
|
||||
// regular colors
|
||||
private static final String BASH_COLOR_BLACK = "\033[0;30m";
|
||||
private static final String BASH_COLOR_RED = "\033[0;31m";
|
||||
private static final String BASH_COLOR_GREEN = "\033[0;32m";
|
||||
private static final String BASH_COLOR_YELLOW = "\033[0;33m";
|
||||
private static final String BASH_COLOR_BLUE = "\033[0;34m";
|
||||
private static final String BASH_COLOR_MAGENTA = "\033[0;35m";
|
||||
private static final String BASH_COLOR_CYAN = "\033[0;36m";
|
||||
private static final String BASH_COLOR_WHITE = "\033[0;37m";
|
||||
// emphasized (bolded) colors
|
||||
private static final String BASH_COLOR_BOLD_BLACK = "\033[1;30m";
|
||||
private static final String BASH_COLOR_BOLD_RED = "\033[1;31m";
|
||||
private static final String BASH_COLOR_BOLD_GREEN = "\033[1;32m";
|
||||
private static final String BASH_COLOR_BOLD_YELLOW = "\033[1;33m";
|
||||
private static final String BASH_COLOR_BOLD_BLUE = "\033[1;34m";
|
||||
private static final String BASH_COLOR_BOLD_MAGENTA = "\033[1;35m";
|
||||
private static final String BASH_COLOR_BOLD_CYAN = "\033[1;36m";
|
||||
private static final String BASH_COLOR_BOLD_WHITE = "\033[1;37m";
|
||||
// background colors
|
||||
private static final String BASH_COLOR_BG_BLACK = "\033[40m";
|
||||
private static final String BASH_COLOR_BG_RED = "\033[41m";
|
||||
private static final String BASH_COLOR_BG_GREEN = "\033[42m";
|
||||
private static final String BASH_COLOR_BG_YELLOW = "\033[43m";
|
||||
private static final String BASH_COLOR_BG_BLUE = "\033[44m";
|
||||
private static final String BASH_COLOR_BG_MAGENTA = "\033[45m";
|
||||
private static final String BASH_COLOR_BG_CYAN = "\033[46m";
|
||||
private static final String BASH_COLOR_BG_WHITE = "\033[47m";
|
||||
// Return to the normal color settings
|
||||
private static final String BASH_COLOR_NORMAL = "\033[0m";
|
||||
// go to the Top of bash
|
||||
private static final String BASH_GO_TOP = "\033[0;0f";
|
||||
|
||||
private static HashMap<String, LogLevel> logLevels = new HashMap<>();
|
||||
|
||||
// to enable color, you need to install in eclipse the plug-in "ANSI escape in console"
|
||||
private static boolean haveColor = true;
|
||||
|
||||
private Logger() {}
|
||||
|
||||
/** 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 logger information */
|
||||
public static String getDrawableName(String libName) {
|
||||
return libName;
|
||||
return String.format("%1$" + 15 + "s", libName);
|
||||
}
|
||||
|
||||
public static boolean getNeedPrint(String libName, LogLevel level) {
|
||||
LogLevel reference = logLevels.get(libName);
|
||||
if (reference == null)
|
||||
return level.isLessEqual(LogLevel.ERROR);
|
||||
return level.isLessEqual(LogLevel.VERBOSE);
|
||||
return level.isLessEqual(reference);
|
||||
}
|
||||
|
||||
public static void print(String libName, String data) {
|
||||
if (haveColor)
|
||||
System.out.print(BASH_COLOR_WHITE);
|
||||
System.out.println("[P] " + libName + " | " + data);
|
||||
if (haveColor)
|
||||
System.out.print(BASH_COLOR_NORMAL);
|
||||
}
|
||||
|
||||
public static void critical(String libName, String data) {
|
||||
if (haveColor)
|
||||
System.out.print(BASH_COLOR_BOLD_RED);
|
||||
System.out.println("[C] " + libName + " | " + data);
|
||||
if (haveColor)
|
||||
System.out.print(BASH_COLOR_NORMAL);
|
||||
}
|
||||
|
||||
public static void error(String libName, String data) {
|
||||
if (haveColor)
|
||||
System.out.print(BASH_COLOR_RED);
|
||||
System.out.println("[E] " + libName + " | " + data);
|
||||
if (haveColor)
|
||||
System.out.print(BASH_COLOR_NORMAL);
|
||||
}
|
||||
|
||||
public static void warning(String libName, String data) {
|
||||
if (haveColor)
|
||||
System.out.print(BASH_COLOR_MAGENTA);
|
||||
System.out.println("[W] " + libName + " | " + data);
|
||||
if (haveColor)
|
||||
System.out.print(BASH_COLOR_NORMAL);
|
||||
}
|
||||
|
||||
public static void info(String libName, String data) {
|
||||
if (haveColor)
|
||||
System.out.print(BASH_COLOR_CYAN);
|
||||
System.out.println("[I] " + libName + " | " + data);
|
||||
if (haveColor)
|
||||
System.out.print(BASH_COLOR_NORMAL);
|
||||
}
|
||||
|
||||
public static void debug(String libName, String data) {
|
||||
if (haveColor)
|
||||
System.out.print(BASH_COLOR_YELLOW);
|
||||
System.out.println("[D] " + libName + " | " + data);
|
||||
if (haveColor)
|
||||
System.out.print(BASH_COLOR_NORMAL);
|
||||
}
|
||||
|
||||
public static void verbose(String libName, String data) {
|
||||
if (haveColor)
|
||||
System.out.print(BASH_COLOR_WHITE);
|
||||
System.out.println("[V] " + libName + " | " + data);
|
||||
if (haveColor)
|
||||
System.out.print(BASH_COLOR_NORMAL);
|
||||
}
|
||||
|
||||
public static void todo(String libName, String data) {
|
||||
if (haveColor)
|
||||
System.out.print(BASH_COLOR_WHITE);
|
||||
System.out.println("[TODO] " + libName + " | " + data);
|
||||
if (haveColor)
|
||||
System.out.print(BASH_COLOR_NORMAL);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user