improve log class
This commit is contained in:
parent
3e08f1a786
commit
e7dd395d29
1 changed files with 49 additions and 57 deletions
|
@ -1,67 +1,59 @@
|
||||||
package fr.insa.clavardator.util;
|
package fr.insa.clavardator.util;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
public class Log {
|
public class Log {
|
||||||
/**
|
/**
|
||||||
* Verbose level: 0 = nothing,
|
* Verbose level: 0 = nothing,
|
||||||
* 1: errors,
|
* 1: errors,
|
||||||
* 2: errors & warnings,
|
* 2: errors & warnings,
|
||||||
* 3: errors & warnings & debug,
|
* 3: errors & warnings & debug,
|
||||||
* 4: all
|
* 4: all
|
||||||
*/
|
*/
|
||||||
public static int verboseLevel = 0;
|
public static int verboseLevel = 0;
|
||||||
|
|
||||||
public static void v(String prefix, String message) {
|
|
||||||
v(prefix, message, null);
|
|
||||||
}
|
|
||||||
public static void v(String prefix, String message, Exception e) {
|
|
||||||
if (verboseLevel >= 4) {
|
|
||||||
Date date = new Date();
|
|
||||||
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss.SSS");
|
|
||||||
System.out.println(sdf.format(date) + " | V | "+ prefix + ": " + message);
|
|
||||||
if (e != null)
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void d(String prefix, String message) {
|
private static void print(String prefix, String message, String mode, int requiredLevel, @Nullable Exception e) {
|
||||||
d(prefix, message, null);
|
if (verboseLevel >= requiredLevel) {
|
||||||
}
|
Date date = new Date();
|
||||||
public static void d(String prefix, String message, Exception e) {
|
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss.SSS");
|
||||||
if (verboseLevel >= 3) {
|
System.out.println(sdf.format(date) + " | " + mode + " | " + prefix + ": " + message);
|
||||||
Date date = new Date();
|
if (e != null)
|
||||||
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss.SSS");
|
e.printStackTrace();
|
||||||
System.out.println(sdf.format(date) + " | D | "+ prefix + ": " + message);
|
}
|
||||||
if (e != null)
|
}
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void w(String prefix, String message) {
|
public static void v(String prefix, String message) {
|
||||||
w(prefix, message, null);
|
v(prefix, message, null);
|
||||||
}
|
}
|
||||||
public static void w(String prefix, String message, Exception e) {
|
|
||||||
if (verboseLevel >= 2) {
|
|
||||||
Date date = new Date();
|
|
||||||
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss.SSS");
|
|
||||||
System.out.println(sdf.format(date) + " | W | "+ prefix + ": " + message);
|
|
||||||
if (e != null)
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void e(String prefix, String message) {
|
public static void v(String prefix, String message, Exception e) {
|
||||||
e(prefix, message, null);
|
print(prefix, message, "V", 4, e);
|
||||||
}
|
}
|
||||||
public static void e(String prefix, String message, Exception e) {
|
|
||||||
if (verboseLevel >= 1) {
|
public static void d(String prefix, String message) {
|
||||||
Date date = new Date();
|
d(prefix, message, null);
|
||||||
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss.SSS");
|
}
|
||||||
System.out.println(sdf.format(date) + " | E | "+ prefix + " " + message);
|
|
||||||
if (e != null)
|
public static void d(String prefix, String message, Exception e) {
|
||||||
e.printStackTrace();
|
print(prefix, message, "D", 3, e);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
public static void w(String prefix, String message) {
|
||||||
|
w(prefix, message, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void w(String prefix, String message, Exception e) {
|
||||||
|
print(prefix, message, "W", 2, e);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void e(String prefix, String message) {
|
||||||
|
e(prefix, message, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void e(String prefix, String message, Exception e) {
|
||||||
|
print(prefix, message, "E", 1, e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue