Spring-Boot logging with log4j2?

membersound picture membersound · Sep 5, 2014 · Viewed 22.6k times · Source

I'm using spring-boot-starter, and would like to configure log4j2.xml to log asynchron + different content to different logfiles.

I created the log4j2 file, but Spring still uses the spring-boot default logging. How can I switch the logging?

Answer

kles4eko picture kles4eko · Dec 13, 2014

I've a better way:

  1. Exclude logback logger:

    <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>
    
  2. Add log4j2 boot starter:

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-log4j2</artifactId>
    </dependency>
    

Source: http://docs.spring.io/spring-boot/docs/1.5.1.RELEASE/reference/htmlsingle/#howto-configure-log4j-for-logging

Enjoy!