-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathColoredOutputExample.java
More file actions
67 lines (56 loc) · 2.47 KB
/
ColoredOutputExample.java
File metadata and controls
67 lines (56 loc) · 2.47 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
package src.examples;
import dev.nebalus.library.jlogger.Logger;
import dev.nebalus.library.jlogger.LogLevel;
import dev.nebalus.library.jlogger.handler.SyslogHandler;
import dev.nebalus.library.jlogger.formatter.ColorLineFormatter;
import dev.nebalus.library.jlogger.formatter.colorscheme.DefaultColorScheme;
import dev.nebalus.library.jlogger.formatter.colorscheme.TrafficLightColorScheme;
/**
* JLogger example demonstrating colored console output with different color
* schemes.
*
* Run with: java -cp "target/classes:examples" ColoredOutputExample
* Note: Colors require a terminal that supports ANSI escape codes.
*/
public class ColoredOutputExample {
/**
* Runs the colored output example demonstrating different color schemes.
*
* @param args command line arguments (not used)
*/
public static void main(String[] args) {
// Create logger
Logger logger = new Logger("ColorDemo");
// --- Using Default Color Scheme ---
System.out.println("=== Default Color Scheme ===\n");
SyslogHandler colorHandler = new SyslogHandler(LogLevel.DEBUG, false);
ColorLineFormatter colorFormatter = new ColorLineFormatter(
new DefaultColorScheme(),
null,
"HH:mm:ss");
colorHandler.setFormatter(colorFormatter);
logger.setHandlers(colorHandler);
// Each level has its own color styling
logger.emergency("EMERGENCY: Blinking yellow on red background");
logger.alert("ALERT: Yellow on bright red background");
logger.fatal("FATAL: White on bright red background");
logger.error("ERROR: Bright red text");
logger.warning("WARNING: Yellow text");
logger.info("INFO: Bright blue text");
logger.log("DEFAULT: No special coloring");
logger.debug("DEBUG: Italic gray text");
// --- Using Traffic Light Color Scheme ---
System.out.println("\n=== Traffic Light Color Scheme ===\n");
colorFormatter.setColorScheme(new TrafficLightColorScheme());
logger.emergency("EMERGENCY: Blinking Red");
logger.alert("ALERT: Bright Red");
logger.fatal("FATAL: Bright Red");
logger.error("ERROR: Yellow");
logger.warning("WARNING: Yellow");
logger.info("INFO: Green");
logger.log("DEFAULT: No special coloring");
logger.debug("DEBUG: Gray");
logger.close();
System.out.println("\n✓ Colored output example completed!");
}
}