Log:logback.xml配置

  Maven 管理的项目,在src/main/resources下新建logback.xml文件。

  1. logback.xml配置
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    <?xml version="1.0" encoding="UTF-8"?>
    <configuration scan="true" scanPeriod="1 seconds" debug="false">
    <timestamp key="bySecond" datePattern="yyyyMMdd'T'HHmmss" />
    <contextName>${bySecond}</contextName>

    <appender name="console" class="ch.qos.logback.core.ConsoleAppender">
    <encoder>
    <!-- <pattern>%-4relative [%thread] %-5level %logger{35} - %msg %n</pattern> -->
    <pattern>logbak: %d{HH:mm:ss.sss} %logger{36} - %msg%n</pattern>
    </encoder>
    </appender>

    <logger name="org.springframework.web" level="DEBUG"/>
    <root level="info">
    <appender-ref ref="console"/>
    </root>

    </configuration>
  2. pom.xml导入logback依赖包
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    <properties>
    <logback.version>1.2.3</logback.version>
    </properties>
    <!-- logback -->
    <dependency>
    <groupId>ch.qos.logback</groupId>
    <artifactId>logback-core</artifactId>
    <version>${logback.version}</version>
    </dependency>
    <dependency>
    <groupId>ch.qos.logback</groupId>
    <artifactId>logback-classic</artifactId>
    <version>${logback.version}</version>
    </dependency>
    <dependency>
    <groupId>ch.qos.logback</groupId>
    <artifactId>logback-access</artifactId>
    <version>${logback.version}</version>
    </dependency>
作者

光星

发布于

2018-03-31

更新于

2022-06-17

许可协议

评论