Repository navigation
Expand file tree
/
Copy pathClrConverter.java
More file actions
54 lines (50 loc) · 1.82 KB
/
Copy pathClrConverter.java
File metadata and controls
54 lines (50 loc) · 1.82 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
package io.github.kloping.qqbot.utils;
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.pattern.color.ANSIConstants;
import ch.qos.logback.core.pattern.color.ForegroundCompositeConverterBase;
import java.util.Locale;
/** Supports Spring Boot-style %clr(value){color} patterns outside Spring Boot. */
public class ClrConverter extends ForegroundCompositeConverterBase<ILoggingEvent> {
@Override
protected String getForegroundColorCode(ILoggingEvent event) {
String color = getFirstOption();
if (color == null) return levelColor(event);
switch (color.toLowerCase(Locale.ROOT)) {
case "black":
return ANSIConstants.BLACK_FG;
case "red":
return ANSIConstants.RED_FG;
case "green":
return ANSIConstants.GREEN_FG;
case "light_green":
case "light-green":
return "92";
case "yellow":
return ANSIConstants.YELLOW_FG;
case "blue":
return ANSIConstants.BLUE_FG;
case "magenta":
return ANSIConstants.MAGENTA_FG;
case "cyan":
return ANSIConstants.CYAN_FG;
case "white":
return ANSIConstants.WHITE_FG;
default:
return ANSIConstants.DEFAULT_FG;
}
}
private String levelColor(ILoggingEvent event) {
switch (event.getLevel().toInt()) {
case 40000:
return ANSIConstants.RED_FG;
case 30000:
return ANSIConstants.YELLOW_FG;
case 20000:
return ANSIConstants.GREEN_FG;
case 10000:
return ANSIConstants.CYAN_FG;
default:
return ANSIConstants.DEFAULT_FG;
}
}
}