zoukankan      html  css  js  c++  java
  • 日志logback

    http://tengj.top/2017/04/05/springboot7/

    ------------------

    logback使用指南。

    公司配置

    <?xml version="1.0" encoding="UTF-8"?>
    <configuration scan="true" scanPeriod="5 seconds" debug="true">
    
        <property resource="${profile.properties}/logback.properties" />
        <appender name="stdoutAppender" class="ch.qos.logback.core.ConsoleAppender">
            <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
                <level>${logback.stdoutLevel}</level>
            </filter>
            <!-- encoder 默认配置为PatternLayoutEncoder -->
            <encoder>
                <pattern>${logback.msg}</pattern>
            </encoder>
        </appender>
    
        <appender name="debugAppender" class="ch.qos.logback.core.rolling.RollingFileAppender">
            <file>${logback.userHome}/${logback.fileName}_${logback.rootLevel}${logback.suffix}</file>
    
            <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
                <level>${logback.rootLevel}</level>
            </filter>
    
            <encoder>
                <pattern>${logback.msg}</pattern>
            </encoder>
    
            <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
                <!-- rollover daily -->
                <fileNamePattern>${logback.userHome}/${logback.fileName}_${logback.rootLevel}_%d{${logback.datePattern}}.%i.log</fileNamePattern>
                <!-- keep ${logback.maxHistory} days' worth of history -->
                <maxHistory>${logback.maxHistory}</maxHistory>
                <timeBasedFileNamingAndTriggeringPolicy
                        class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
                    <!-- or whenever the file size reaches ${logback.maxFileSize} -->
                    <maxFileSize>${logback.maxFileSize}</maxFileSize>
                </timeBasedFileNamingAndTriggeringPolicy>
            </rollingPolicy>
        </appender>
    
        <appender name="noticelog" class="ch.qos.logback.core.rolling.RollingFileAppender">
            <File>${logback.userHome}/notice_${logback.rootLevel}.log</File>
    
            <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
                <level>${logback.rootLevel}</level>
            </filter>
    
            <encoder>
                <pattern>${logback.msg}</pattern>
            </encoder>
    
            <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
                <FileNamePattern>${logback.userHome}/notice_${logback.rootLevel}_%d{${logback.datePattern}}.%i.log</FileNamePattern>
                <maxHistory>${logback.maxHistory}</maxHistory>
                <timeBasedFileNamingAndTriggeringPolicy
                        class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
                    <maxFileSize>${logback.maxFileSize}</maxFileSize>
                </timeBasedFileNamingAndTriggeringPolicy>
            </rollingPolicy>
        </appender>
        <logger name="NOTICE-LOG" additivity="false" level="debug">
            <appender-ref ref="noticelog"/>
            <appender-ref ref="debugAppender" />
        </logger>
    
        <logger name="org.apache.activemq" level="WARN" additivity="false">
            <appender-ref ref="debugAppender" />
        </logger>
    
        <logger name="org.apache.zookeeper" level="WARN" additivity="false">
            <appender-ref ref="debugAppender"/>
        </logger>
    
        <!-- TRACE, DEBUG, INFO, WARN, ERROR, ALL 和 OFF -->
        <root level="${logback.rootLevel}">
            <appender-ref ref="stdoutAppender" />
            <appender-ref ref="debugAppender" />
        </root>
    </configuration>

    配置文件

    logback.msg=%date [%thread] [%X{uid} - %X{url}] %-5level %logger{80} - %msg%n
    logback.suffix=.log
    logback.fileName=${project.artifactId}
    logback.userHome=./logs/${project.artifactId}
    #The date-and-time pattern, as found within the accolades of %d{} follow java.text.SimpleDateFormat conventions
    logback.datePattern=yyyy-MM-dd
    #keep ${logback.maxHistory} 'logback.datePattern' worth of history
    logback.maxHistory=30
    logback.maxFileSize=200MB
    #TRACE, DEBUG, INFO, WARN, ERROR, ALL, OFF
    logback.stdoutLevel=debug
    logback.rootLevel=debug
  • 相关阅读:
    2017-2018-2 20179205 《网络攻防》第十三周作业 国密算法实现
    2017-2018-2 20179205 《网络攻防技术与实践》第十二周作业 免杀技术
    2017-2018-2 20179205《网络攻防技术与实践》第十一周作业 SQL注入攻击与实践
    2017-2018-2 20179205《网络攻防技术与实践》第十周作业 缓冲区溢出攻防研究
    2017-2018-2 20179205《网络攻防技术与实践》第九周作业
    2017-2018-2 20179205 《网络攻防技术与实践》第八周作业
    2017-2018-2 20179205 《网络攻防技术与实践》第七周作业
    2017-2018-2 20179205《网络攻防技术与实践》Windows攻击实验
    2017-2018-2 20179205 《网络攻防技术与实践》第六周作业
    2017-2018-2 20179205 《网络攻防技术与实践》第五周作业
  • 原文地址:https://www.cnblogs.com/pingh/p/8435208.html
Copyright © 2011-2022 走看看