I have a log4j2.xml file as follows. It's working, but it's picking up a lot of Hibernate and GWT log files. How can I exclude those packages, or how can I have my logfile only include logging from my package hierarchy?
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="INFO">
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n" />
</Console>
<File name="FileAllLogs" fileName="logs/MyProj_all.txt" immediateFlush="true" append="true">
<PatternLayout pattern="%d{yyy-MM-dd HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
</File>
<File name="FileAllErrors" fileName="logs/MyProj_errors.txt" immediateFlush="true" append="true">
<PatternLayout pattern="%d{yyy-MM-dd HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
</File>
</Appenders>
<Loggers>
<Root level="debug">
<AppenderRef ref="Console" />
<AppenderRef ref="FileAllLogs"/>
</Root>
<Root level="error">
<AppenderRef ref="FileAllErrors"/>
</Root>
</Loggers>
</Configuration>
Remove your "debug" root logger. And then add following logger which will log only logs from the given "some.dummy.package"
<logger name="some.dummy.package" level="debug" additivity="false">
<AppenderRef ref="Console" />
<AppenderRef ref="FileAllLogs"/>
</logger>
So in finally you will have
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="INFO">
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n" />
</Console>
<File name="FileAllLogs" fileName="logs/MyProj_all.txt" immediateFlush="true" append="true">
<PatternLayout pattern="%d{yyy-MM-dd HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
</File>
<File name="FileAllErrors" fileName="logs/MyProj_errors.txt" immediateFlush="true" append="true">
<PatternLayout pattern="%d{yyy-MM-dd HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
</File>
</Appenders>
<Loggers>
<Root level="error">
<AppenderRef ref="FileAllErrors"/>
</Root>
<Logger name="some.dummy.package" level="debug" additivity="false">
<AppenderRef ref="Console" />
<AppenderRef ref="FileAllLogs"/>
</Logger>
</Loggers>
</Configuration>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With