美文网首页
第3章 Logback的配置与使用

第3章 Logback的配置与使用

作者: cuzz_ | 来源:发表于2018-04-26 19:06 被阅读0次

    Logback的主要模块

    • logback-access
    • logback-classic
    • logback-core

    Logback的主要标签

    • logger
    • appender
    • layout

    Logback的配置

    <?xml version="1.0" encoding="utf-8" standalone="no"?>
    <configuration debug="false">
        <appender name="INFO-FILE"
                  class="ch.qos.logback.core.rolling.RollingFileAppender">
            <file>${catalina.base}/webapps/o2o/logs/info/info.log</file>
            <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
                <fileNamePattern>${catalina.base}/webapps/o2o/logs/info/info.%d{yyyy-MM-dd}.%i.log.zip</fileNamePattern>
                <timeBasedFileNamingAndTriggeringPolicy
                        class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
                    <maxFileSize>1024MB</maxFileSize>
                </timeBasedFileNamingAndTriggeringPolicy>
                <maxHistory>30</maxHistory>
            </rollingPolicy>
            <layout class="ch.qos.logback.classic.PatternLayout">
                <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{55} -
                    %msg%n
                </pattern>
            </layout>
        </appender>
        <appender name="ACCESS-FILE"
                  class="ch.qos.logback.core.rolling.RollingFileAppender">
            <file>
                ${catalina.base}/webapps/o2o/logs/access/access.log</file>
            <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
                <FileNamePattern>${catalina.base}/webapps/o2o/logs/access/access.%d{yyyy-MM-dd}.%i.log.zip</FileNamePattern>
                <timeBasedFileNamingAndTriggeringPolicy
                        class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
                    <maxFileSize>1024MB</maxFileSize>
                </timeBasedFileNamingAndTriggeringPolicy>
                <maxHistory>30</maxHistory>
            </rollingPolicy>
            <layout class="ch.qos.logback.classic.PatternLayout">
                <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{55} -
                    %msg%n
                </pattern>
            </layout>
        </appender>
        <logger name="com.imooc.o2o" level="DEBUG" additivity="false">
            <appender-ref ref="ACCESS-FILE" />
        </logger>
        <root level="INFO">
            <appender-ref ref="INFO-FILE" />
        </root>
    </configuration>
    

    相关文章

      网友评论

          本文标题:第3章 Logback的配置与使用

          本文链接:https://www.haomeiwen.com/subject/gqsjlftx.html