[DEV] add dispaly backtrace and store critical occured (add gradle too)
This commit is contained in:
parent
e9543d24ee
commit
0ed47849fb
6
.gitattributes
vendored
Normal file
6
.gitattributes
vendored
Normal file
@ -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
|
||||||
|
|
6
.gitignore
vendored
6
.gitignore
vendored
@ -15,3 +15,9 @@ build.number
|
|||||||
/.settings/
|
/.settings/
|
||||||
/junit/
|
/junit/
|
||||||
/target/
|
/target/
|
||||||
|
|
||||||
|
# Ignore Gradle project-specific cache directory
|
||||||
|
.gradle
|
||||||
|
|
||||||
|
# Ignore Gradle build output directory
|
||||||
|
build
|
||||||
|
86
build.gradle
Normal file
86
build.gradle
Normal file
@ -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
|
||||||
|
}
|
||||||
|
|
2
settings.gradle
Normal file
2
settings.gradle
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
|
||||||
|
rootProject.name = 'scenarium-logger'
|
@ -26,7 +26,9 @@ public class Logger {
|
|||||||
|
|
||||||
// background colors
|
// background colors
|
||||||
private static final String BASH_COLOR_BG_BLACK = "\033[40m";
|
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_BLUE = "\033[44m";
|
||||||
|
|
||||||
private static final String BASH_COLOR_BG_CYAN = "\033[46m";
|
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_GREEN = "\033[42m";
|
||||||
private static final String BASH_COLOR_BG_MAGENTA = "\033[45m";
|
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_RED = "\033[0;31m";
|
||||||
private static final String BASH_COLOR_WHITE = "\033[0;37m";
|
private static final String BASH_COLOR_WHITE = "\033[0;37m";
|
||||||
private static final String BASH_COLOR_YELLOW = "\033[0;33m";
|
private static final String BASH_COLOR_YELLOW = "\033[0;33m";
|
||||||
|
|
||||||
// go to the Top of bash
|
// go to the Top of bash
|
||||||
private static final String BASH_GO_TOP = "\033[0;0f";
|
private static final String BASH_GO_TOP = "\033[0;0f";
|
||||||
|
static boolean criticalOccured = false;
|
||||||
|
|
||||||
private static LogLevel defaultLevel = LogLevel.INFO;
|
private static LogLevel defaultLevel = LogLevel.INFO;
|
||||||
private static boolean haveClassName = false;
|
private static boolean haveClassName = false;
|
||||||
// to enable color, you need to install in eclipse the plug-in "ANSI escape in console"
|
// 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 haveFileName = true;
|
||||||
private static boolean haveLibName = true;
|
private static boolean haveLibName = true;
|
||||||
private static boolean haveLineNumber = true;
|
private static boolean haveLineNumber = true;
|
||||||
@ -73,7 +76,6 @@ public class Logger {
|
|||||||
private static WrapInt sizeLineNumber = new WrapInt(3);
|
private static WrapInt sizeLineNumber = new WrapInt(3);
|
||||||
private static WrapInt sizeThreadId = new WrapInt(2);
|
private static WrapInt sizeThreadId = new WrapInt(2);
|
||||||
private static WrapInt sizeThreadName = new WrapInt(10);
|
private static WrapInt sizeThreadName = new WrapInt(10);
|
||||||
|
|
||||||
static {
|
static {
|
||||||
// Load system color state
|
// Load system color state
|
||||||
String value = System.getProperty("logger.color");
|
String value = System.getProperty("logger.color");
|
||||||
@ -127,6 +129,7 @@ public class Logger {
|
|||||||
}
|
}
|
||||||
System.out.print(Logger.BASH_COLOR_NORMAL);
|
System.out.print(Logger.BASH_COLOR_NORMAL);
|
||||||
System.out.flush();
|
System.out.flush();
|
||||||
|
Logger.criticalOccured = true;
|
||||||
System.exit(-50);
|
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) {
|
public static void error(final String libName, final String data) {
|
||||||
if (Logger.haveColor) {
|
if (Logger.haveColor) {
|
||||||
System.out.print(Logger.BASH_COLOR_RED);
|
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) {
|
public static void print(final String libName, final String data) {
|
||||||
if (Logger.haveColor) {
|
if (Logger.haveColor) {
|
||||||
System.out.print(Logger.BASH_COLOR_WHITE);
|
System.out.print(Logger.BASH_COLOR_WHITE);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user