log4j 2 为控制台追加器添加多种颜色
2022-08-31 23:48:54
嗨,我刚刚下载并配置了log4j-2。我被困在将颜色代码应用于控制台附加器上。我的控制台附加器如下所示。SlowConsole
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} %-5level %logger{36} - %msg%n"/>
</Console>
<Console name="SlowConsole" target="SYSTEM_OUT">
<PatternLayout pattern="%highlight{%d{HH:mm:ss.SSS} %-5level %logger{36}.%M() @%L - %msg%n}{FATAL=red, ERROR=red, WARN=yellow, INFO=black, DEBUG=green, TRACE=blue}"/>
</Console>
<File name="File" fileName="C:\log\out.txt">
<PatternLayout pattern="%d{HH:mm:ss.SSS} %-5level %logger{36} - %msg%n" />
</File>
</Appenders>
<Loggers>
<logger name="org.abc.ea.web" level="ALL" additivity="false">
<!--Log4j for the WEB MODULE -->
<appender-ref ref="SlowConsole"/>
</logger>
<logger name="org.abc.ea.ejb" level="ALL" additivity="false">
<!--Log4j for the EJB MODULE -->
<appender-ref ref="SlowConsole"/>
</logger>
<Root level="ERROR">
<AppenderRef ref="Console"/>
<AppenderRef ref="File" />
</Root>
</Loggers>
</Configuration>
我有两个问题,
我是log4j的新手,这是编写xml配置文件的正确方法吗?
-
如何为每个日志级别添加两个颜色代码?
例如:DEBUG=绿色 -> 将输出浅绿色字体,但我需要它和
dim
bold