Max Semikin
Max Semikin

Reputation: 974

Log4j2 log levels not being filtered for hibernate and spring in Spring Boot application

I have configured Spring Boot to use Log4j2 according to this manual. I would like to filter all the logs by the level set in the Root logger. Here is my log4j2-spring.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<Configuration>
    <Properties>
        <Property name="LOG_PATTERN">%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} -s %msg%n</Property>
    </Properties>
    <Appenders>
        <Console name="Console">
            <PatternLayout pattern="${LOG_PATTERN}"/>
        </Console>
        <File name="File" fileName="app.log">
            <PatternLayout pattern="${LOG_PATTERN}"/>
        </File>
        <SMTP name="Mail"
              ...
        >
            <ThresholdFilter level="ERROR" onMatch="ACCEPT"/>
            <PatternLayout pattern="${LOG_PATTERN}"/>
        </SMTP>
    </Appenders>
    <Loggers>
        <Root level="INFO">
            <AppenderRef ref="Console"/>
            <AppenderRef ref="File"/>
            <AppenderRef ref="Mail"/>
        </Root>
    </Loggers>
</Configuration>

The problem is that I still see DEBUG output from hibernate and spring framework. I managed to filter individual logs by specifying full package names for some entries like this:

<Loggers>
    <Logger name="org.springframework.boot.context.web" level="INFO" />
    <Root level="INFO">
        <AppenderRef ref="Console"/>
        <AppenderRef ref="File"/>
        <AppenderRef ref="Mail"/>
    </Root>
</Loggers>

However of course it's not feasible to do it for all the packages. Thanks for any help!

Upvotes: 3

Views: 1031

Answers (1)

Max Semikin
Max Semikin

Reputation: 974

Finally fixed it. The problem was that I had a line debug=true in application.properties file and the filter in log4j2-spring.xml config was simply ignored.

Upvotes: 1

Related Questions