-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLogger.java
More file actions
92 lines (73 loc) · 2.36 KB
/
Copy pathLogger.java
File metadata and controls
92 lines (73 loc) · 2.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package net.cvs0.utils;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
public class Logger
{
private static final String RESET = "\u001B[0m";
private static final String RED = "\u001B[31m";
private static final String GREEN = "\u001B[32m";
private static final String YELLOW = "\u001B[33m";
private static final String BLUE = "\u001B[34m";
private static final String PURPLE = "\u001B[35m";
private static final String CYAN = "\u001B[36m";
private static final String WHITE = "\u001B[37m";
private static boolean enableColors = true;
private static boolean enableTimestamps = true;
private static DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern("HH:mm:ss");
public static void info(String message)
{
log("INFO", message, BLUE);
}
public static void success(String message)
{
log("SUCCESS", message, GREEN);
}
public static void warn(String message)
{
log("WARN", message, YELLOW);
}
public static void error(String message)
{
log("ERROR", message, RED);
}
public static void debug(String message)
{
log("DEBUG", message, CYAN);
}
public static void trace(String message)
{
log("TRACE", message, PURPLE);
}
private static void log(String level, String message, String color)
{
StringBuilder sb = new StringBuilder();
if (enableTimestamps) {
sb.append("[").append(LocalDateTime.now().format(timeFormatter)).append("] ");
}
if (enableColors) {
sb.append(color);
}
sb.append("[").append(level).append("]");
if (enableColors) {
sb.append(RESET);
}
sb.append(" ").append(message);
if ("ERROR".equals(level)) {
System.err.println(sb.toString());
} else {
System.out.println(sb.toString());
}
}
public static void setEnableColors(boolean enableColors)
{
Logger.enableColors = enableColors;
}
public static void setEnableTimestamps(boolean enableTimestamps)
{
Logger.enableTimestamps = enableTimestamps;
}
public static void setTimeFormatter(DateTimeFormatter formatter)
{
Logger.timeFormatter = formatter;
}
}