将 log4j.properties 转换为 log4j2.xml

发布于 2025-01-12 12:30:50 字数 1752 浏览 1 评论 0原文

我从未处理过此类问题,现在我应该将 log4j.properties 文件移植到 log4j2.xml 中,但我遇到了很多问题。

有什么工具可以用于此目的吗?或者任何指南,因为我真的被困在这里了。

我必须转移的一些 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"

如果有人可以帮我翻译上面的这些属性,我相信我可以自己翻译其他属性,因为它们与这些属性类似。

提前致谢!

I never worked with this type of issue and now I'm supposed to port log4j.properties file into log4j2.xml and I'm having bunch of problems.

Is there any tool that I could use for this? Or any guide because I'm really stuck here.

List of some Log4j.properties that I have to transfer:

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"

If someone could help me translate these properties from above, I believe I would be able to translate others by myself because they're similar to these.

Thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

陈甜 2025-01-19 12:30:50

我没有找到可以将 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>

I didn't find tool that would translate log4j.properties file into log4j2.xml but manual translation ended up being quite simple.

Example for loggers:

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

Will become:

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

Example for appenders:

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

Will become:

<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>

So entire log4j2.xml file based on this example should look like this:

<?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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文