From 0ed47849fb31f4af29ab87f9192e3a52d4abb0f4 Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Mon, 3 May 2021 17:04:49 +0200 Subject: [PATCH] [DEV] add dispaly backtrace and store critical occured (add gradle too) --- .gitattributes | 6 ++ .gitignore | 6 ++ build.gradle | 86 +++++++++++++++++++++++++++++ settings.gradle | 2 + src/io/scenarium/logger/Logger.java | 22 +++++++- 5 files changed, 119 insertions(+), 3 deletions(-) create mode 100644 .gitattributes create mode 100644 build.gradle create mode 100644 settings.gradle diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..00a51af --- /dev/null +++ b/.gitattributes @@ -0,0 +1,6 @@ +# +# https://help.github.com/articles/dealing-with-line-endings/ +# +# These are explicitly windows files and should use crlf +*.bat text eol=crlf + diff --git a/.gitignore b/.gitignore index d075be7..ca56ada 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,9 @@ build.number /.settings/ /junit/ /target/ + +# Ignore Gradle project-specific cache directory +.gradle + +# Ignore Gradle build output directory +build diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..fd80ed3 --- /dev/null +++ b/build.gradle @@ -0,0 +1,86 @@ +/* + * This file was generated by the Gradle 'init' task. + * + * This generated file contains a sample Java library project to get you started. + * For more details take a look at the 'Building Java & JVM projects' chapter in the Gradle + * User Manual available at https://docs.gradle.org/6.8.3/userguide/building_java_projects.html + */ +import com.github.jk1.license.render.* + +plugins { + id 'java-library' + id 'com.adarshr.test-logger' version '3.0.0' +} + +sourceSets { + main { + buildDir 'out/gradle' + java { + srcDir 'src' + } + resources { + srcDir 'resources' + } + version = rootProject.file('scenarium-logger/version.txt').text.trim() + } + test { + java { + srcDir 'test/src' + } + resources { + srcDir 'test/resources' + } + } +} + +repositories { + // Use JCenter for resolving dependencies. + jcenter() + google() +} + +dependencies { + // Use JUnit Jupiter API for testing. + testImplementation 'org.junit.jupiter:junit-jupiter-api:5.6.2' + + // Use JUnit Jupiter Engine for testing. + testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine' + + } + +tasks.named('test') { + // Use junit platform for unit tests. + useJUnitPlatform() +} + + +tasks.named('jar') { + manifest { + attributes('Implementation-Title': project.name, + 'Implementation-Version': project.version) + } +} + + +task sourcesJar(type: Jar, dependsOn: classes) { + classifier = 'sources' + from sourceSets.main.allSource +} + +task javadocJar(type: Jar, dependsOn: javadoc) { + classifier = 'javadoc' + from javadoc.destinationDir +} + +testlogger { + showFullStackTraces true + showSimpleNames true + // pick a theme - mocha, standard, plain, mocha-parallel, standard-parallel or plain-parallel + theme 'mocha' +} + +artifacts { + archives sourcesJar + archives javadocJar +} + diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 0000000..b5ff51f --- /dev/null +++ b/settings.gradle @@ -0,0 +1,2 @@ + +rootProject.name = 'scenarium-logger' diff --git a/src/io/scenarium/logger/Logger.java b/src/io/scenarium/logger/Logger.java index 9fb2dc8..9ca2666 100644 --- a/src/io/scenarium/logger/Logger.java +++ b/src/io/scenarium/logger/Logger.java @@ -26,7 +26,9 @@ public class Logger { // 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"; @@ -53,13 +55,14 @@ public class Logger { 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 = false; + private static boolean haveColor = true; private static boolean haveFileName = true; private static boolean haveLibName = true; private static boolean haveLineNumber = true; @@ -73,7 +76,6 @@ public class Logger { 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"); @@ -127,6 +129,7 @@ public class Logger { } System.out.print(Logger.BASH_COLOR_NORMAL); System.out.flush(); + Logger.criticalOccured = true; System.exit(-50); } @@ -140,6 +143,15 @@ public class Logger { } } + public static void displayBackTrace(final String libNameDraw) { + 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) { if (Logger.haveColor) { System.out.print(Logger.BASH_COLOR_RED); @@ -227,6 +239,10 @@ public class Logger { } } + public static boolean isCriticalOccured() { + return Logger.criticalOccured; + } + public static void print(final String libName, final String data) { if (Logger.haveColor) { System.out.print(Logger.BASH_COLOR_WHITE);