将log4j.properties转换为log4j.xml[英] Converting log4j.properties to log4j.xml

本文是小编为大家收集整理的关于将log4j.properties转换为log4j.xml的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

我找不到如何在log4j.xml中指定常数的任何地方.例如,我在log4j.properties中具有这个常数:

#Log directory
dal.log.dir=/var/log/pojodal/
# Log filename
dal.log.file=pojodal.log

我在属性文件的其他部分中使用这些常数如下:

log4j.appender.DRFA1.File=${dal.log.dir}/${dal.log.file}

如何在log4j.xml中实现相同的行为?

推荐答案

您可以使用此在线服务转换完整 log4j.properties ,您可以在其中粘贴log4j.properties,按转换并复制新的:

http://log4j-props2xml.appspot.com/

如果该WebApp脱机...您也可以在自己的servlet容器中启动它...您在这里找到下载和来源:

https://github.com/jrogyals/log4j-properties-converter/a >

在log4j.xml中使用变量:

这在答案向另一个问题 ...使用 xml内部实体 在这里使用 java系统属性 在这里.

其他推荐答案

您可以将日志文件位置和名称设置为log4j xml

中的参数元素
<param name="File" value="C:\\logs\\application\\ApplicationLog.log" />

下面的示例文件:

<log4j:configuration>
    <appender name="STDOUT" class="org.apache.log4j.RollingFileAppender">
        <param name="File"     value="C:\\logs\\application\\ApplicationLog.${user.name}.log" />
        <param name="MaxFileSize" value="5000KB" />
        <param name="MaxBackupIndex" value="10" />
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern"
        value="[%d{yyyy-MMM-dd HH:mm:ss}] [%t] %-5p %c{1}: %m %n" />
        </layout>
        <filter class="org.apache.log4j.varia.LevelRangeFilter">
            <param name="LevelMin" value="DEBUG"/>
            <param name="LevelMax" value="FATAL"/>
        </filter>
    </appender>

    <root>
        <level value="all" />
        <appender-ref ref="STDOUT"/>
    </root>
</log4j:configuration>

本文地址:https://www.itbaoku.cn/post/1574824.html

问题描述

I couldn't find anywhere how to specify constants in log4j.xml. For example, I have this constant in my log4j.properties:

#Log directory
dal.log.dir=/var/log/pojodal/
# Log filename
dal.log.file=pojodal.log

And I use these constants as follows, in other parts of the properties file:

log4j.appender.DRFA1.File=${dal.log.dir}/${dal.log.file}

How to achieve the same behavior in log4j.xml?

推荐答案

You can convert your complete log4j.properties using this online service, where you can paste your log4j.properties, press convert and copy your new log4j.xml:

http://log4j-props2xml.appspot.com/

If that webapp is offline ... you can also start it in your own servlet container ... you find downloads and sources here:

https://github.com/jroyals/log4j-properties-converter/

Use of variables in log4j.xml:

This is explained in an answer to another question ... using XML internal entities here and using Java System Properties here.

其他推荐答案

You can set the log file location and name as a parameter element in the log4J xml

<param name="File" value="C:\\logs\\application\\ApplicationLog.log" />

Example file below:

<log4j:configuration>
    <appender name="STDOUT" class="org.apache.log4j.RollingFileAppender">
        <param name="File"     value="C:\\logs\\application\\ApplicationLog.${user.name}.log" />
        <param name="MaxFileSize" value="5000KB" />
        <param name="MaxBackupIndex" value="10" />
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern"
        value="[%d{yyyy-MMM-dd HH:mm:ss}] [%t] %-5p %c{1}: %m %n" />
        </layout>
        <filter class="org.apache.log4j.varia.LevelRangeFilter">
            <param name="LevelMin" value="DEBUG"/>
            <param name="LevelMax" value="FATAL"/>
        </filter>
    </appender>

    <root>
        <level value="all" />
        <appender-ref ref="STDOUT"/>
    </root>
</log4j:configuration>