Add Logger class
This commit is contained in:
parent
0ff7d63a4b
commit
3e08f1a786
1 changed files with 67 additions and 0 deletions
67
src/main/java/fr/insa/clavardator/util/Log.java
Executable file
67
src/main/java/fr/insa/clavardator/util/Log.java
Executable 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();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue