gpt4 book ai didi

java - 如何配置 log4j.xml 以从 log4j 迁移到 log4j2?

转载 作者:行者123 更新时间:2023-12-05 04:47:14 24 4
gpt4 key购买 nike

<分区>

我正在开发一个到目前为止一直在使用 log4j 的应用程序,我想迁移到 log4j2 。我是 log4j 2 的新手,引用 log4j 1.x migration guide 但对于某些部分,我不清楚我的 log4j.xml 中的配置应该如何。

当前的 log4j.xml 文件如下所示:


<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">

<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">

<!-- Appender for logging to console output -->
<appender name="consoleAppender" class="org.apache.log4j.ConsoleAppender">
<param name="Threshold" value="debug" />
<layout class="org.apache.log4j.EnhancedPatternLayout">
<param name="ConversionPattern" value="[%d{dd-MMM-yyyy HH:mm:ss:SSS}][%5p][%c{1}:%L]- %m%n" />
</layout>
</appender>

<!-- Appender for logging audit messages to the file -->
<appender name="auditLoggerAppender" class="org.apache.log4j.rolling.RollingFileAppender">
<param name="Threshold" value="debug" />

<rollingPolicy class="org.apache.log4j.rolling.TimeBasedRollingPolicy">
<param name="ActiveFileName" value="C:/logs/Filename.log" />
<param name="FileNamePattern" value="C:/logs/Filename2.%d.log" />
<param name="MaxHistory" value="30" />
</rollingPolicy>

<layout class="org.apache.log4j.EnhancedPatternLayout">
<param name="ConversionPattern" value="[%d{dd-MMM-yyyy HH:mm:ss:SSS}][%5p][%c{1}:%L]- %m%n" />
</layout>
</appender>

<!-- Logger for audit messages -->
<logger name="auditLogger" additivity="false">
<appender-ref ref="applicationLoggerAppender" />
</logger>


</log4j:configuration>

需要对 <param><layout><RollinFileAppender> 部分和 <logger name="auditLogger" additivity="false"> <appender-ref ref="applicationLoggerAppender" /> </logger> 进行哪些配置更改才能与 log4j 2 一起使用?

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com