logback的简单配置详解



<configuration scan="true" scanPeriod="30 seconds">

    
    <property name="LOG_HOME" value="/data/logs/sys_admin"/>
    
    
    <property name="ENCODER_PATTERN"
              value="%d{yyyy-MM-dd HH:mm:ss.SSS} %X{traceId} %level %logger{0} [%t] %m%n"/>
    
    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
            <pattern>${ENCODER_PATTERN}pattern>
        encoder>
    appender>

    
    
    <appender name="INFO_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
        
        <Append>trueAppend>
        
        <file>${LOG_HOME}/sys_info.logfile>
        
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            
            <FileNamePattern>${LOG_HOME}/sys_info.log.%d{yyyy-MM-dd}FileNamePattern>
            
            <MaxHistory>30MaxHistory>
        rollingPolicy>
        
        <encoder>
            <pattern>${ENCODER_PATTERN}pattern>
            <charset>UTF-8charset>
        encoder>
        
        <filter class="ch.qos.logback.classic.filter.LevelFilter">
            
            <level>INFOlevel>
            
            <onMatch>ACCEPTonMatch>
            
            <onMismatch>DENYonMismatch>
        filter>
    appender>

    
    <appender name="ERROR_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <Append>trueAppend>
        <file>${LOG_HOME}/sys_error.logfile>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            
            <FileNamePattern>${LOG_HOME}/sys_error.log.%d{yyyy-MM-dd}
            FileNamePattern>
            
            <MaxHistory>30MaxHistory>
        rollingPolicy>
        <encoder>
            <pattern>${ENCODER_PATTERN}pattern>
            <charset>UTF-8charset>
        encoder>
        <filter class="ch.qos.logback.classic.filter.LevelFilter">
            <level>ERRORlevel>
            <onMatch>ACCEPTonMatch>
            <onMismatch>DENYonMismatch>
        filter>
    appender>

    
    <appender name="WARN_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <Append>trueAppend>
        <file>${LOG_HOME}/sys_warn.logfile>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            
            <FileNamePattern>${LOG_HOME}/sys_warn.log.%d{yyyy-MM-dd}
            FileNamePattern>
            
            <MaxHistory>30MaxHistory>
        rollingPolicy>
        <encoder>
            <pattern>${ENCODER_PATTERN}pattern>
            <charset>UTF-8charset>
        encoder>
        <filter class="ch.qos.logback.classic.filter.LevelFilter">
            <level>WARNlevel>
            <onMatch>ACCEPTonMatch>
            <onMismatch>DENYonMismatch>
        filter>
    appender>

    <appender name="DEBUG_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <Append>trueAppend>
        <file>${LOG_HOME}/sys_debug.logfile>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            
            <FileNamePattern>${LOG_HOME}/sys_debug.log.%d{yyyy-MM-dd}
            FileNamePattern>
            
            <MaxHistory>30MaxHistory>
        rollingPolicy>
        <encoder>
            <pattern>${ENCODER_PATTERN}pattern>
            <charset>UTF-8charset>
        encoder>
        <filter class="ch.qos.logback.classic.filter.LevelFilter">
            <level>DEBUGlevel>
            <onMatch>ACCEPTonMatch>
            <onMismatch>DENYonMismatch>
        filter>
    appender>

    <appender name="trace" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>/data/logs/trace/trace.logfile>
        <Append>trueAppend>
        <encoder>
            
            <pattern>%msg%npattern>
            <charset>UTF-8charset>
        encoder>

        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            
            <FileNamePattern>/data/logs/trace/trace.log.%d{yyyy-MM-dd-HH}FileNamePattern>
            
            <MaxHistory>1MaxHistory>
        rollingPolicy>
    appender>

    
    <appender name="async-trace" class="ch.qos.logback.classic.AsyncAppender">
        
        <discardingThreshold>80discardingThreshold>
        
        <queueSize>512queueSize>
        
        <appender-ref ref="trace"/>
    appender>

    
    <logger name="cn.system.trace.utils.SpanLogger" additivity="false">
        <level value="INFO"/>
        <appender-ref ref="async-trace"/>
    logger>

    <logger name="cn.system.jade.datasource.SQLParseInfo" additivity="false">
        <level value="INFO"/>
        <appender-ref ref="WARN_FILE"/>
    logger>

    
    
    <root>
        
        <level value="INFO"/>
        
        <appender-ref ref="STDOUT"/>
        
        <appender-ref ref="INFO_FILE"/>
        <appender-ref ref="WARN_FILE"/>
        <appender-ref ref="ERROR_FILE"/>
        <appender-ref ref="DEBUG_FILE"/>
    root>
configuration>

你可能感兴趣的:(logback,java)