[DEV] reorganize some files

This commit is contained in:
Edouard DUPIN 2021-03-29 00:07:12 +02:00
parent 5283c25564
commit 21d515ca99
4 changed files with 297 additions and 189 deletions

View File

@ -10,13 +10,13 @@
<setting id="org.eclipse.jdt.core.formatter.comment.new_lines_at_block_boundaries" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_logical_operator" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_parameters" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.comment.insert_new_line_for_parameter" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_package" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.comment.insertNew_line_for_parameter" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insertNew_line_after_annotation_on_package" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.parentheses_positions_in_method_invocation" value="common_lines"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_enum_constant" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.blank_lines_after_imports" value="1"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_while" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.comment.insert_new_line_before_root_tags" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.comment.insertNew_line_before_root_tags" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_annotation_type_member_declaration" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_throws" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.parentheses_positions_in_switch_statement" value="common_lines"/>
@ -49,11 +49,11 @@
<setting id="org.eclipse.jdt.core.formatter.comment.count_line_length_from_starting_position" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_return" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_method_declaration" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_parameter" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insertNew_line_after_annotation_on_parameter" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_arrow_in_switch_case" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.wrap_before_multiplicative_operator" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.keep_then_statement_on_same_line" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_field" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insertNew_line_after_annotation_on_field" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_explicitconstructorcall_arguments" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_prefix_operator" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.blank_lines_between_type_declarations" value="1"/>
@ -61,14 +61,14 @@
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_for" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_catch" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_arguments" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_method" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insertNew_line_after_annotation_on_method" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_switch" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_parameterized_type_references" value="0"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_anonymous_type_declaration" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_logical_operator" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_parenthesized_expression" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.keep_annotation_declaration_on_one_line" value="one_line_if_empty"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_enum_constant" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insertNew_line_after_annotation_on_enum_constant" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_multiplicative_operator" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.never_indent_line_comments_on_first_column" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_and_in_type_parameter" value="insert"/>
@ -91,7 +91,7 @@
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_type_declaration" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_for" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.comment.preserve_white_space_between_code_and_line_comments" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_local_variable" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insertNew_line_after_annotation_on_local_variable" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_method_declaration" value="end_of_line"/>
<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_abstract_method" value="1"/>
<setting id="org.eclipse.jdt.core.formatter.keep_enum_constant_declaration_on_one_line" value="one_line_if_empty"/>
@ -128,7 +128,7 @@
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_catch" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_invocation" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_bitwise_operator" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.put_empty_statement_on_new_line" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.put_empty_statement_onNew_line" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_parameters_in_constructor_declaration" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_type_parameters" value="0"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_invocation_arguments" value="insert"/>
@ -136,10 +136,10 @@
<setting id="org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_constructor_declaration" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_compact_loops" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_block_comment" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_catch_in_try_statement" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insertNew_line_before_catch_in_try_statement" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_try" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.keep_simple_for_body_on_same_line" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_at_end_of_file_if_missing" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insertNew_line_at_end_of_file_if_missing" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_javadoc_comment" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_relational_operator" value="0"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_array_initializer" value="insert"/>
@ -173,18 +173,18 @@
<setting id="org.eclipse.jdt.core.formatter.keep_if_then_body_block_on_one_line" value="one_line_if_empty"/>
<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_first_class_body_declaration" value="0"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_conditional_expression" value="80"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_closing_brace_in_array_initializer" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insertNew_line_before_closing_brace_in_array_initializer" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_parameters" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.format_guardian_clause_on_one_line" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_if" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.align_assignment_statements_on_columns" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_type" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insertNew_line_after_annotation_on_type" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_block" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_enum_declaration" value="end_of_line"/>
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_block_in_case" value="end_of_line"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_arrow_in_switch_default" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_constructor_declaration" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.comment.insert_new_line_between_different_tags" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.comment.insertNew_line_between_different_tags" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_conditional_expression_chain" value="0"/>
<setting id="org.eclipse.jdt.core.formatter.comment.format_header" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression" value="16"/>
@ -236,7 +236,7 @@
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_switch" value="end_of_line"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_superinterfaces" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_parameters" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_type_annotation" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insertNew_line_after_type_annotation" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_brace_in_array_initializer" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_parenthesized_expression" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.comment.format_html" value="true"/>
@ -254,11 +254,11 @@
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_declarations" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.keep_empty_array_initializer_on_one_line" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_switch" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_else_in_if_statement" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insertNew_line_before_else_in_if_statement" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_assignment_operator" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_constructor_declaration" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_new_chunk" value="1"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_label" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.blank_lines_beforeNew_chunk" value="1"/>
<setting id="org.eclipse.jdt.core.formatter.insertNew_line_after_label" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_declaration_header" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_allocation_expression" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_constructor_declaration" value="do not insert"/>
@ -270,12 +270,12 @@
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_arrow_in_switch_case" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_assert" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_member_type" value="1"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_while_in_do_statement" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insertNew_line_before_while_in_do_statement" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_logical_operator" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_type_reference" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_parameterized_type_reference" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_qualified_allocation_expression" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_opening_brace_in_array_initializer" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insertNew_line_after_opening_brace_in_array_initializer" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.indent_breaks_compare_to_cases" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_declaration" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.wrap_before_bitwise_operator" value="true"/>
@ -353,7 +353,7 @@
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_question_in_conditional" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.comment.indent_parameter_description" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.number_of_blank_lines_at_beginning_of_code_block" value="0"/>
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_finally_in_try_statement" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insertNew_line_before_finally_in_try_statement" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.tabulation.char" value="tab"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_relational_operator" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_field_declarations" value="do not insert"/>

13
logger.iml Normal file
View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/test/src" isTestSource="true" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" scope="TEST" name="org.junit.jupiter:junit-jupiter-api:5.7.1" level="project" />
</component>
</module>

View File

@ -8,6 +8,7 @@
******************************************************************************/
package io.scenarium.logger;
import java.nio.CharBuffer;
import java.util.HashMap;
import java.util.List;
@ -15,65 +16,271 @@ import io.scenarium.logger.internal.Log;
@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";
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_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_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";
private static HashMap<String, LogLevel> logLevels = new HashMap<>();
private static LogLevel defaultLevel = LogLevel.CRITICAL;
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 = false;
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<String, LogLevel> 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("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
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("logger.level");
if (value != null) {
LogLevel level = LogLevel.fromString(value);
final LogLevel level = LogLevel.fromString(value);
System.out.println("Change global level at " + value + " ==> " + level);
Logger.defaultLevel = level;
}
}
private Logger() {}
private static String addGeneric(final String level, final String libName) {
String out = level;
out += Logger.printElement("", "", Logger.haveLibName, libName, Logger.sizeLibName);
out += Logger.printElement(" | ", "", Logger.haveThreadId, Long.toString(Thread.currentThread().getId()), Logger.sizeThreadId);
out += Logger.printElement(" | ", "", Logger.haveThreadName, Thread.currentThread().getName(), Logger.sizeThreadName);
if (Logger.haveClassName || Logger.haveFileName || Logger.haveLineNumber) {
final StackTraceElement callElem = Logger.getCallerElement();
out += Logger.printElementLeft(" | l=", "", Logger.haveLineNumber, Long.toString(callElem.getLineNumber()), Logger.sizeLineNumber);
out += Logger.printElement(" | ", "", Logger.haveClassName, callElem.getClassName(), Logger.sizeClassName);
out += Logger.printElement(" | ", "", Logger.haveFileName, callElem.getFileName(), Logger.sizeFileName);
}
return out;
}
public static void critical(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();
System.exit(-50);
}
public static void debug(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 error(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() {
return Thread.currentThread().getStackTrace()[5];
}
/** 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(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) {
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<String> 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 --logger-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 logger 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 void print(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();
}
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;
}
public static String spaces(final int spaces) {
return CharBuffer.allocate(spaces).toString().replace('\0', ' ');
}
public static void todo(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");
@ -96,136 +303,25 @@ public class Logger {
Log.print("");
}
/** Initialize the library with generic argument in command line
* @param args list of argument that are filtered after */
public static void init(List<String> args) {
if (isInit)
return;
isInit = true;
for (int iii = 0; iii < args.size(); ++iii) {
String data = args.get(iii);
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("--log-color"))
Logger.haveColor = true;
else if (data.contentEquals("--log-no-color"))
Logger.haveColor = false;
else if (data.startsWith("--log-lib=")) {
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 --logger-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]));
logLevels.put(values[0], LogLevel.fromString(values[1]));
}
public static void verbose(final String libName, final String data) {
if (Logger.haveColor) {
System.out.print(Logger.BASH_COLOR_WHITE);
}
// Clear all logger elements.
int iii = 0;
while (iii < args.size()) {
String data = args.get(iii);
if (data.startsWith("--log"))
args.remove(iii);
else
iii++;
System.out.println(Logger.addGeneric("[V] ", libName) + " | " + data);
if (Logger.haveColor) {
System.out.print(Logger.BASH_COLOR_NORMAL);
}
}
/** 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 String.format("%1$" + 15 + "s", libName);
public static void warning(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);
}
}
public static boolean getNeedPrint(String libName, LogLevel level) {
LogLevel reference = logLevels.get(libName);
if (reference == null)
return level.isLessEqual(Logger.defaultLevel);
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);
System.out.flush();
}
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);
System.out.flush();
if (haveColor)
System.out.print(BASH_COLOR_YELLOW);
for (StackTraceElement ste : Thread.currentThread().getStackTrace())
System.out.println(ste);
System.out.print(BASH_COLOR_NORMAL);
System.out.flush();
System.out.flush();
System.exit(-50);
}
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);
}
private Logger() {}
}

View File

@ -13,10 +13,9 @@ import java.util.List;
import io.scenarium.logger.Logger;
import org.junit.Test;
import org.junit.jupiter.api.MethodOrderer.OrderAnnotation;
import org.junit.jupiter.api.Order;
//import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;
@TestMethodOrder(OrderAnnotation.class)