简体   繁体   中英

Spring boot logging with log4j - how do I ENABLE spring boot log entries?

I configured spring boot to use log4j with these lines in pom.xml:

    <!-- use log4j instead of logback (spring boots own logging) -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter</artifactId>
        <exclusions>
            <exclusion>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-logging</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-log4j</artifactId>
    </dependency>

I stopped spring from logging at debug level to console by configuring my log4j.xml like that:

<root>
    <priority value="ERROR" />
    <appender-ref ref="consoleAppender" />
</root>

My question is what do I have to put into log4j.xml to get to see log messages from spring boot? This was not working for example (addition to log4j.xml):

<category name="org.springframework.web">
    <level value="trace" />
</category>

What is the correct path or the correct method to get spring boot to log again using log4j?

I think it's <logger> not <category> . Note that Spring Boot also saves you from having to remember that by making log levels configurable in application.properties.

It looks like you should have set the Error level to Info Level if you want to standard Spring output.

From the Log4J quick start site https://logging.apache.org/log4j/1.2/manual.html

This rule is at the heart of log4j. It assumes that levels are ordered. For the standard levels, we have DEBUG < INFO < WARN < ERROR < FATAL

So root should probably look like this

<root>
    <level value="Info" />
    <appender-ref ref="console" />
</root>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM