嗨,我刚刚下载并配置了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>
我有两个问题,
例如:DEBUG = green->将输出浅绿色字体,但是我需要它是
dim
和bold
最佳答案
我想我找到了解决方案。我下载了log4j2-core-sources.jar并跟踪了source。您可以如下编写:
<Console name="SlowConsole" target="SYSTEM_OUT">
<PatternLayout disableAnsi="false" pattern="%highlight{%d{HH:mm:ss.SSS} %-5level %logger{36}.%M() @%L - %msg%n}{FATAL=red blink, ERROR=red, WARN=yellow bold, INFO=black, DEBUG=green bold, TRACE=blue}"/>
</Console>
我认为log4j2 documentation及其示例可能需要更新。