正在将www.example.com转换log4j.properties为log4j2.xml

4jb9z9bj  于 2022-11-06  发布在  其他
关注(0)|答案(1)|浏览(204)

我从来没有处理过这种类型的问题,现在我应该把log4j.properties文件移植到log4j2.xml中,我遇到了一堆问题。
有没有什么工具可以帮我?或者任何指导,因为我真的被困在这里了。
我必须传输的一些www.example.com的列表Log4j.properties:

log4j.additivity.com.company.areas.audit.config.auditors.TransactionAuditor=false;
(Bunch of lines like these below, with different paths)
log4j.logger.net.sf=WARN, FILE,FILE_ERROR,CONSOLE
log4j.logger.xxxx.yyyy.zzzz = ERROR,FILE,FILE_ERROR,CONSOLE
log4j.logger.aaaa.bbbb.cccc = INFO, FILE,FILE_ERROR,CONSOLE
log4j.appender.CONSOLE.Threshold=OFF
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} [%t] %-5p - %m%n
log4j.appender.FILE=org.apache.log4j.RollingFileAppender
log4j.appender.FILE.File=${base.path}/logs/application.log
log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
log4j.appender.FILE.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} [%t] %-5p - %m%n
log4j.appender.FILE.MaxFileSize=100000KB
log4j.appender.FILE.MaxBackupIndex=5
log4j.appender.FILE_PERFORMANCE=org.apache.log4j.RollingFileAppender
log4j.appender.FILE_PERFORMANCE.File=${base.path}/logs/application_performance.log
log4j.appender.FILE_PERFORMANCE.layout=org.apache.log4j.PatternLayout
log4j.appender.FILE_PERFORMANCE.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} [%t] %-5p - %m%n
log4j.appender.FILE_PERFORMANCE.MaxFileSize=10000KB
log4j.appender.FILE_PERFORMANCE.MaxBackupIndex=2
(and bunch of similar stuff but for example instead of FILE_PERFORMACE I have things like: "FILE_ERROR" -> log4j.appender.FILE_ERROR = org.apache.log4j.RollingFileAppender", "FILE_INTEGRATION" etc"

如果有人能帮我翻译上面的这些性质,我相信我也能自己翻译其他的,因为它们和这些很相似。
提前感谢!

gz5pxeao

gz5pxeao1#

我没有找到可以将 log4j.properties 文件转换为 log4j2.xml 的工具,但手动转换非常简单。

记录器示例:

log4j.additivity.com.exm.tst.audit.config.auditors.TransactionAuditor=false
log4j.logger.com.exm.tst.audit.config.auditors.TransactionAuditor=ERROR, FILE

将变成:

<Logger name="com.exm.tst.audit.config.auditors.TransactionAuditor" 
   additivity="false" level="ERROR">
   <appender-ref ref="FILE"/>
</Logger>

附加器示例:

log4j.appender.FILE=org.apache.log4j.RollingFileAppender
log4j.appender.FILE.File=${catalina.base}/logs/application.log
log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
log4j.appender.FILE.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} [%t] %-5p - %m%n
log4j.appender.FILE.MaxFileSize=100000KB
log4j.appender.FILE.MaxBackupIndex=5

将变成:

<RollingFile name="FILE" fileName="${sys:catalina.home}/logs/application.log"
    filePattern="${sys:catalina.home}/logs/application.%i.log.gz" >
    <PatternLayout pattern="${LOG_PATTERN}"/>
    <Policies>
        <SizeBasedTriggeringPolicy size="10000KB" />
    </Policies>
    <DefaultRolloverStrategy max="5"/>
</RollingFile>

因此,基于此示例的整个log4j2.xml文件应如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN" monitorInterval="30">

    <!-- Logging Properties -->
    <Properties>
        <Property name="LOG_PATTERN">%d{yyyy-MM-dd HH:mm:ss} [%t] %-5p - %m%n</Property>
    </Properties>

    <Appenders>

        <RollingFile name="FILE" fileName="${sys:catalina.home}/logs/application.log"
            filePattern="${sys:catalina.home}/logs/application.%i.log.gz" >
            <PatternLayout pattern="${LOG_PATTERN}"/>
            <Policies>
                <SizeBasedTriggeringPolicy size="10000KB" />
            </Policies>
            <DefaultRolloverStrategy max="5"/>
        </RollingFile>

    </Appenders>

    <Loggers>

        <Logger name="com.exm.tst.audit.config.auditors.TransactionAuditor" 
           additivity="false" level="ERROR">
           <appender-ref ref="FILE"/>
        </Logger>

    </Loggers>

</Configuration>

相关问题