Spring Boot 日志实现

2022-07-15  本文已影响0人  Tinyspot

1. Spring Boot 日志实现

默认 SLF4J + Logback, 默认 INFO 级别
需引入依赖 spring-boot-starter-logging

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

Spring Boot 项目中 spring-boot-starter 中包含 spring-boot-starter-logging,所以无需单独引入

spring-boot-log.png

1.1 配置文件

# application.properties
logging.level.com.example.concrete=info
logging.pattern.console=%d{yyyy-MM-dd HH:mm:ss.SSS} %5level %c %M %L %thread %m%n
# directory
logging.file.path=/Users/tinyspot/Downloads/log
logging.pattern.file=%d{yyyy-MM-dd HH:mm:ss.SSS} %5level %c %M %L %thread %m%n

1.2 替换为 Log4j 2

<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-log4j2</artifactId>
</dependency>
上一篇下一篇

猜你喜欢

热点阅读