我有两个包com.temp1和com.temp2都使用spring,hibernate和其他一些jar文件。我想获得两个包的单独日志文件。我能在代码中改变什么。
log4j2.xml
onDestroy()
日志初始化java类
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xml>
<Configuration status="debug">
<Appenders>
<RollingFile name="log_A" fileName="${path}/A_temp.log"
filePattern="${path}/A_temp-%d{yyyy-MM-dd}-%i.log.gz">
<PatternLayout>
<pattern><![CDATA[%d{MM-dd HH:mm:ss} "%-17c" "%m"%n]]>
</pattern>
</PatternLayout>
</RollingFile>
<RollingFile name="log_B" fileName="${path}/B_temp.log"
filePattern="${path}/B_temp-%d{yyyy-MM-dd}-%i.log.gz">
<PatternLayout>
<pattern><![CDATA["${hostName}" "${userName}" %d{yyyy-MM-dd HH:mm:ss} "%-17c" "%m"%n]]>
</pattern>
</PatternLayout>
</RollingFile>
</Appenders>
<Loggers>
<Logger name="com.temp1" level="debug">
<appender-ref ref="log_A" level="debug"/>
</Logger>
<Logger name="com.temp2" level="debug">
<appender-ref ref="log_B" level="debug"/>
</Logger>
</Loggers>
</Configuration>