Add Logger class

This commit is contained in:
Yohan Simard 2020-12-14 15:26:44 +01:00
parent 0ff7d63a4b
commit 3e08f1a786

View file

@ -0,0 +1,67 @@
package fr.insa.clavardator.util;
import java.text.SimpleDateFormat;
import java.util.Date;
public class Log {
/**
* Verbose level: 0 = nothing,
* 1: errors,
* 2: errors & warnings,
* 3: errors & warnings & debug,
* 4: all
*/
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) {
d(prefix, message, null);
}
public static void d(String prefix, String message, Exception e) {
if (verboseLevel >= 3) {
Date date = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss.SSS");
System.out.println(sdf.format(date) + " | D | "+ prefix + ": " + message);
if (e != null)
e.printStackTrace();
}
}
public static void w(String prefix, String message) {
w(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) {
e(prefix, message, null);
}
public static void e(String prefix, String message, Exception e) {
if (verboseLevel >= 1) {
Date date = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss.SSS");
System.out.println(sdf.format(date) + " | E | "+ prefix + " " + message);
if (e != null)
e.printStackTrace();
}
}
}