membersound
membersound

Reputation: 86905

How to configure the logging framework in Spring-Boot?

How can I tell Spring-Boot which logging framework to use? (I want to use log4j2).

In 1.1.9.RELEASE I just had a log4j2.xml in my classpath and the logging worked.

Now I upgraded to spring-boot-1.2.0.RELEASE, and my loggers do not work anymore! Maybe I have to configure the logging framework to be used explicit?

I'm using org.apache.logging.log4j.LogManager.getRootLogger() for logging, maybe this is wrong?

Upvotes: 3

Views: 1473

Answers (2)

Ben M
Ben M

Reputation: 1892

You should be using SFL4J which is a level of abstraction around the actual logging implementation used. if you configure your POM as above, and include the appropriate log4j configuration in src/main/resources, and log using a org.slf4j.Logger then you should be fine

Upvotes: 0

Evgeni Dimitrov
Evgeni Dimitrov

Reputation: 22516

See the docs: http://docs.spring.io/spring-boot/docs/current/reference/html/howto-logging.html#howto-configure-log4j-for-logging

Just change the POM

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>
<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-log4j2</artifactId>
</dependency>

Upvotes: 2

Related Questions