---
title: "Spring boot 2.0替换默认日志框架logback到 Slf4j + log4j2"
author: "jdkleo"
date: "2018-11-29T17:13:15Z"
tags: []
categories: ["编程语言"]
slug: "spring-boot-2-0-logback-slf4j-log4j2"
draft: false
lastmod: "2018-12-14T13:36:35Z"
id: 2434517
url: "https://jdkleo.iteye.com/blog/2434517"
---

第一步  移除默认日志加载依赖

```
<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-aop</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-test</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-web</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-cache</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-jdbc</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-logging</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
 <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-logging</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
```

 第二步  增加slf4j + log4j2依赖

 

`<!--支持log4j2异步日志必需 -->`

`<dependency>`

`<groupId>com.lmax</groupId>`

`<artifactId>disruptor</artifactId>`

`</dependency>`

` ` 

`<!-- 日志API框架slf4j核心包-->` 

`<dependency>`

`<groupId>org.slf4j</groupId>`

`<artifactId>slf4j-api</artifactId>`

`</dependency>`

`<dependency>`

`<groupId>org.slf4j</groupId>`

`<artifactId>jcl-over-slf4j</artifactId>`

`</dependency>`

`    ` 

`<!--增加log4j2依赖-->` 

`<dependency>`

`<groupId>org.springframework.boot</groupId>`

`<artifactId>spring-boot-starter-log4j2</artifactId>`

`</dependency>`