Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Filtering out Hibernate logs in Log4j2 file

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>
like image 417
Stealth Rabbi Avatar asked Jan 29 '15 16:01

Stealth Rabbi


1 Answers

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>
like image 192
Babl Avatar answered Nov 14 '22 22:11

Babl