将JUL相关的log4j 1.2配置转换为log4j 2配置

Convert log4j 1.2 configuration related to JUL to log4j 2 configuration

我正在将应用程序从 log4j 1.2 转换为 log4j2。在 log4j.properties 文件中,我发现了以下与 Java 实用日志相关的配置。

handlers=java.util.logging.ConsoleHandler
java.util.logging.ConsoleHandler.level=SEVERE

如何将此配置转换为 log4j2 配置?

谢谢!

Log4j2 provides a bridge to route all calls to the java.util.logging API to Log4j2. To activate this, set the system property java.util.logging.manager to org.apache.logging.log4j.jul.LogManager and add the Log4j2 JUL adapter jar to your classpath (see "which jars FAQ").

然后像往常一样配置log4j2。 log4j2手册提供了很多示例配置。

您提供的配置片段可能会转换为如下所示(我添加了一个 FileAppender 作为示例)。

<Configuration status="warn"><!-- use status="trace" for troubleshooting -->
  <Appenders>
    <Console name="STDOUT" target="SYSTEM_OUT">
      <PatternLayout pattern="%m%n"/>
    </Console>
    <File name="FILE" fileName="myapp.log">
      <PatternLayout>
        <pattern>%d %p [%t] %c{1.} %m%n</pattern>
      </PatternLayout>
    </File>
  </Appenders>
  <Loggers>
    <Root level="trace">
      <AppenderRef ref="STDOUT" level="ERROR" />
      <AppenderRef ref="FILE" />
    </Root>
  </Loggers>
</Configuration>