如何使用不同的 log4j 转换模式在不同的包中记录消息并使用相同的文件进行输出。
以下是我的配置文件,请建议如何修改以使用不同的转换模式
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration debug="true" xmlns:log4j='http://jakarta.apache.org/log4j/'>
<appender name="PLUGIN_FILE" class="LoggerTest.NewLogForEachRunFileAppender">
<!-- Below param sets the dir path of the log files -->
<param name="FileDirPath" value ="/var/opt/mycomp/ftpm/" />
<!-- Below param sets the suffix name for the log file -->
<param name="FileNameSuffix" value="_error.log" />
<param name="MaxFileSize" value="10KB"/>
<!-- Below param creates the specified number of backup files to be created when rolled back -->
<param name="MaxBackupIndex" value="10"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%-4r %d [%t] %-5.37c %M() %L %x %m%n" />
</layout>
<filter class="org.apache.log4j.varia.LevelRangeFilter">
<param name="LevelMin" value="debug" />
<param name="LevelMax" value="fatal" />
<param name="AcceptOnMatch" value="true" />
</filter>
</appender>
<appender name="ERROR_FILE" class="LoggerTest.NewLogForEachRunFileAppender">
<!-- Below param sets the dir path of the log files -->
<param name="FileDirPath" value ="/var/opt/mycomp/ftpm/" />
<!-- Below param sets the suffix name for the log file -->
<param name="FileNameSuffix" value="_error.log"/>
<param name="MaxFileSize" value="10KB"/>
<!-- Below param creates the specified number of backup files to be created when rolled back -->
<param name="MaxBackupIndex" value="10"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d [%t] - %m%n" />
</layout>
<filter class="org.apache.log4j.varia.LevelRangeFilter">
<param name="LevelMin" value="error" />
<param name="LevelMax" value="fatal" />
<param name="AcceptOnMatch" value="true" />
</filter>
</appender>
<logger name="LoggerTest.a" additivity="false">
<appender-ref ref="PLUGIN_FILE"/>
</logger>
<root>
<level value="error" />
<appender-ref ref="ERROR_FILE" />
<!-- To enable the trace messages for debugging uncomment the below appender ref statement -->
<level value="DEBUG" />
<appender-ref ref="DEBUG_FILE" />
</root>
</log4j:configuration>