log4j动态指定log输出路径

 

log4j.xml如下:

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

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

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

 

<appender name="ALL" class="org.apache.log4j.RollingFileAppender">

<param name="File" value="${loggingRoot}/all.log" />

<param name="MaxFileSize" value="1MB" />

<param name="MaxBackupIndex" value="5" /> 

<layout class="org.apache.log4j.PatternLayout">

</layout>

</appender>

<appender name="appender1" class="org.apache.log4j.RollingFileAppender">

<param name="File" value="${loggingRoot}/xj.log" />

<param name="MaxFileSize" value="1MB" />

<param name="MaxBackupIndex" value="5" />

<layout class="org.apache.log4j.PatternLayout">

</layout>

</appender>

<logger name="control" additivity="false">

<level value="debug" />

<appender-ref ref="appender1" />

</logger>

 

<root>

<level value="error" />

<appender-ref ref="ALL" />

</root>

</log4j:configuration>  

 

 

在启动时添加java_opts项 -DloggingRoot=D:/WebApp/shopping_mvn/output/logs

你可能感兴趣的:(apache,log4j,xml)