problem description
the original project uses log4j to manage logs, but now it cannot automatically output exception information to the log file after being upgraded to log4j2.
the environmental background of the problems and what methods you have tried
now you can manually catch exceptions and print exception messages to the console and log files via logger.error ("", e);), but the project is too big and it takes too much time to modify it, so you want to capture it automatically like log4j and output it to the log file.
related codes
log4j2 profile
<?xml version="1.0" encoding="UTF-8"?>
<!-- log4j2 -->
<!-- trace<debug<info<warn<error<fatal -->
<configuration status="debug">
<!-- -->
<Properties>
<!-- -->
<Property name="pattern">%d{yyyy-MM-dd HH:mm:ss,SSS} (%F:%L) %5p %m%n</Property>
<!-- -->
<Property name="filePath">D:/Tomcat 6.0/log4j/equipmentLease/</Property>
<!-- debug -->
<Property name="debugFileName">${filePath}/debug.log</Property>
<!-- info -->
<Property name="infoFileName">${filePath}/info.log</Property>
<!-- error -->
<Property name="errorFileName">${filePath}/error.log</Property>
</Properties>
<!-- -->
<appenders>
<!-- -->
<Console name="console" target="SYSTEM_OUT">
<!-- -->
<PatternLayout pattern="${pattern}"/>
</Console>
<!-- debug -->
<RollingFile name="debug_appender" fileName="${debugFileName}"
filePattern="${filePath}/%d{yyyy-MM-dd}/debug_%i.log">
<!-- -->
<Filters>
<!-- debuginfo -->
<ThresholdFilter level="debug"/>
<ThresholdFilter level="info" onMatch="DENY" onMismatch="NEUTRAL"/>
</Filters>
<!-- -->
<PatternLayout pattern="${pattern}"/>
<!-- -->
<Policies>
<!-- -->
<TimeBasedTriggeringPolicy interval="1" modulate="true"/>
<!-- -->
<SizeBasedTriggeringPolicy size="100 MB"/>
</Policies>
</RollingFile>
<!-- info -->
<RollingFile name="info_appender" fileName="${infoFileName}"
filePattern="${filePath}/%d{yyyy-MM-dd}/info_%i.log">
<!-- -->
<Filters>
<!-- infoerror -->
<ThresholdFilter level="info"/>
<ThresholdFilter level="error" onMatch="DENY" onMismatch="NEUTRAL"/>
</Filters>
<!-- -->
<PatternLayout pattern="${pattern}"/>
<!-- -->
<Policies>
<!-- -->
<TimeBasedTriggeringPolicy interval="1" modulate="true"/>
<!-- -->
<SizeBasedTriggeringPolicy size="100 MB"/>
</Policies>
</RollingFile>
<!-- error -->
<RollingFile name="error_appender" fileName="${errorFileName}"
filePattern="${filePath}/%d{yyyy-MM-dd}/error_%i.log">
<!-- -->
<Filters>
<!-- error -->
<ThresholdFilter level="error"/>
</Filters>
<!-- -->
<PatternLayout pattern="${pattern}"/>
<Policies>
<!-- -->
<TimeBasedTriggeringPolicy interval="1" modulate="true"/>
<!-- -->
<SizeBasedTriggeringPolicy size="100 MB"/>
</Policies>
</RollingFile>
</appenders>
<!-- logger -->
<loggers>
<!-- logger -->
<!-- debug appender -->
<Root level="debug">
<!-- -->
<AppenderRef ref="console"/>
<!-- debug -->
<AppenderRef ref="debug_appender"/>
<!-- info -->
<AppenderRef ref="info_appender"/>
<!-- error -->
<AppenderRef ref="error_appender"/>
</Root>
</loggers>
</configuration>