improve log class
This commit is contained in:
parent
3e08f1a786
commit
e7dd395d29
1 changed files with 49 additions and 57 deletions
|
@ -1,5 +1,7 @@
|
|||
package fr.insa.clavardator.util;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
|
@ -13,55 +15,45 @@ public class Log {
|
|||
*/
|
||||
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) {
|
||||
private static void print(String prefix, String message, String mode, int requiredLevel, @Nullable Exception e) {
|
||||
if (verboseLevel >= requiredLevel) {
|
||||
Date date = new Date();
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss.SSS");
|
||||
System.out.println(sdf.format(date) + " | V | "+ prefix + ": " + message);
|
||||
System.out.println(sdf.format(date) + " | " + mode + " | " + prefix + ": " + message);
|
||||
if (e != null)
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void v(String prefix, String message) {
|
||||
v(prefix, message, null);
|
||||
}
|
||||
|
||||
public static void v(String prefix, String message, Exception e) {
|
||||
print(prefix, message, "V", 4, e);
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
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) {
|
||||
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();
|
||||
}
|
||||
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) {
|
||||
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();
|
||||
}
|
||||
print(prefix, message, "E", 1, e);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue