logback日志

<?xml version="1.0" encoding="UTF-8" ?>        
<configuration  scan="true" scanPeriod="60 seconds" debug="false">
    <contextName>logback</contextName>
    <property name="log.path" value="log" />
    <!--输出到控制台-->
    <appender name="console" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>%d{HH:mm:ss.SSS} %contextName [%thread] %-5level %logger{36} - %msg%n</pattern>
        </encoder>
    </appender>

    <!--输出到文件-->
    <appender name="file" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <!--D:\\log\\logback.%d{yyyy-MM-dd}.log本地磁盘绝对路径,${log.path}/logback.%d{yyyy-MM-dd}.log项目中的相对路径-->
            <fileNamePattern>${log.path}/logback.%d{yyyy-MM-dd}.log</fileNamePattern>
        </rollingPolicy>
        <encoder>
            <pattern>%d{HH:mm:ss.SSS} %contextName [%thread] %-5level %logger{36} - %msg%n</pattern>
        </encoder>
    </appender>

    <root level="info">
        <appender-ref ref="console" />
        <appender-ref ref="file" />
    </root>

    <!-- logback为java中的包 -->
    <logger name="com.mico.emptyspringboot.controller"/>
    <!--logback.LogbackDemo:类的全路径 -->
    <logger name="com.mico.emptyspringboot.controller.UserController" level="WARN" additivity="false">
        <appender-ref ref="console"/>
    </logger>
</configuration>
<!--spring-boot-starter-log4j2 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
<version>2.2.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>

#application.properties引入此xml
logging.config=classpath:Logback.xml

注意:要和lombok插件配置和使用最佳

posted @ 2020-01-07 12:03  LY-留言  阅读(144)  评论(0编辑  收藏  举报