我想要一个 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="ConsoleAppender" class="org.apache.log4j.ConsoleAppender">
<param name="Threshold" value="DEBUG" />
<param name="Target" value="System.out" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{dd-MM-yyyy HH:mm:ss} %-5p%c{1} - %m%n" />
</layout>
</appender>
<appender name="LogFileAppender" class="org.apache.log4j.RollingFileAppender">
<param name="File" value="${log-base-dir}/${adapter-name}.log" />
<param name="MaxFileSize" value="5000KB" />
<param name="MaxBackupIndex" value="99" />
<param name="append" value="true" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{dd-MM-yyyy HH:mm:ss} %-5p%c{1} - %m%n" />
</layout>
</appender>
<root>
<level value="info" />
<appender-ref ref="ConsoleAppender" />
<appender-ref ref="LogFileAppender" />
</root>
</log4j:configuration>