Spring boot集成logback

application.properties配置:

  • logging.config=classpath:logback.xml
    logging.path=logs/youpath

logback.xml配置:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <!--<property resource="logback.properties" />-->

    <appender name="Console" class="ch.qos.logback.core.ConsoleAppender">
        <Target>System.out</Target>
        <encoder>
            <pattern>%d [%t] %p %logger - %m%n</pattern>
        </encoder>
        <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
            <level>DEBUG</level>
        </filter>
    </appender>
    <appender name="LogFile" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <Append>true</Append>
        <encoder>
            <pattern>%d [%t] %p %logger{0} - %m%n</pattern>
        </encoder>
        <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
            <level>INFO</level>
        </filter>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <fileNamePattern>${log.path}/xxx-log.%d{yyyy-MM-dd}.log</fileNamePattern>
            <maxHistory>30</maxHistory>
        </rollingPolicy>
    </appender>
    <appender name="ErrorFile" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <encoder>
            <pattern>%d [%t] %p %logger{0} - %m%n</pattern>
        </encoder>
        <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
            <level>ERROR</level>
        </filter>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <fileNamePattern>${log.path}/xxx-error.%d{yyyy-MM-dd}.log</fileNamePattern>
            <maxHistory>30</maxHistory>
        </rollingPolicy>
    </appender>

    <!--<logger name="org.springframework" level="DEBUG"/>-->
    <!--<logger name="org.apache" level="DEBUG"/>-->
    <!--<logger name="org.mybatis.spring" level="DEBUG"/>-->

    <root level="INFO">
        <appender-ref ref="Console"/>
        <appender-ref ref="LogFile"/>
        <appender-ref ref="ErrorFile"/>
    </root>
</configuration>




个人资料
时海
等级:8
文章:272篇
访问:16.0w
排名: 2
上一篇: 人工智能在搜索中的应用
下一篇:java实现图片裁剪缩放工具类
标签: logback、appender、qos、ch、level、面试题
隐藏