logback.xml配置

方式1:


<configuration>
    <include resource="org/springframework/boot/logging/logback/defaults.xml" />
    <property name="FILE_LOG_PATTERN" value="%d{yyyy-MM-dd HH:mm:ss.SSS}|%level|%t|%line|%-40.40logger{39}:%m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}"/>
    <springProperty scope="context" name="LOG_LEVEL" source="logback.level" defaultValue="INFO"/>
    <springProperty scope="context" name="LOG_HOME" source="logback.fileDir"/>
    
    <property name="LOG_FILE_NAME" value="tbm-compose_daily"/>
    
    <property name="COMPRESSION_TYPE" value="zip"/>
    
    <property name="MAX_FILE_SIZE" value="100MB"/>
    
    <property name="MAX_HISTORY" value="30"/>
 
 
    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS}|%level|%t|%line|%-40.40logger{39}:%m%npattern>
            <charset>utf8charset>
        encoder>
    appender>
    
    <appender name="info" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${LOG_HOME}/${LOG_FILE_NAME}_info.logfile>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            
            <FileNamePattern>${LOG_HOME}/info/${LOG_FILE_NAME}.%d{yyyy-MM-dd}.%i.${COMPRESSION_TYPE}
            FileNamePattern>
            
            <MaxHistory>${MAX_HISTORY}MaxHistory>
            
            <timeBasedFileNamingAndTriggeringPolicy
                    class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
                <maxFileSize>${MAX_FILE_SIZE}maxFileSize>
            timeBasedFileNamingAndTriggeringPolicy>
        rollingPolicy>
        <append>trueappend>
        <encoder>
            <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%npattern>
            <charset>utf-8charset>
        encoder>
        <filter class="ch.qos.logback.classic.filter.LevelFilter">
            <level>INFOlevel>
            <onMatch>ACCEPTonMatch>
            <onMismatch>DENYonMismatch>
        filter>
    appender>
    
    <appender name="error" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${LOG_HOME}/${LOG_FILE_NAME}_error.logfile>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            
            <FileNamePattern>${LOG_HOME}/error/${LOG_FILE_NAME}.%d{yyyy-MM-dd}.%i.${COMPRESSION_TYPE}
            FileNamePattern>
            
            <MaxHistory>${MAX_HISTORY}MaxHistory>
            
            <timeBasedFileNamingAndTriggeringPolicy
                    class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
                <maxFileSize>${MAX_FILE_SIZE}maxFileSize>
            timeBasedFileNamingAndTriggeringPolicy>
        rollingPolicy>
        <append>trueappend>
        <encoder>
            <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS}|%level|%t|%line|%-40.40logger{39}:%m%npattern>
            <charset>utf-8charset>
        encoder>
        <filter class="ch.qos.logback.classic.filter.LevelFilter">
            <level>ERRORlevel>
            <onMatch>ACCEPTonMatch>
            <onMismatch>DENYonMismatch>
        filter>
    appender>
    
    <appender name="warn" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${LOG_HOME}/${LOG_FILE_NAME}_warn.logfile>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            
            <FileNamePattern>${LOG_HOME}/warn/${LOG_FILE_NAME}.%d{yyyy-MM-dd}.%i.${COMPRESSION_TYPE}
            FileNamePattern>
            
            <MaxHistory>${MAX_HISTORY}MaxHistory>
            
            <timeBasedFileNamingAndTriggeringPolicy
                    class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
                <maxFileSize>${MAX_FILE_SIZE}maxFileSize>
            timeBasedFileNamingAndTriggeringPolicy>
        rollingPolicy>
        <append>trueappend>
        <encoder>
            <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS}|%level|%t|%line|%-40.40logger{39}:%m%npattern>
            <charset>utf-8charset>
        encoder>
        <filter class="ch.qos.logback.classic.filter.LevelFilter">
            <level>WARNlevel>
            <onMatch>ACCEPTonMatch>
            <onMismatch>DENYonMismatch>
        filter>
    appender>
    
    <appender name="debug" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${LOG_HOME}/${LOG_FILE_NAME}_debug.logfile>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            
            <FileNamePattern>${LOG_HOME}/debug/${LOG_FILE_NAME}.%d{yyyy-MM-dd}.%i.${COMPRESSION_TYPE}
            FileNamePattern>
            
            <MaxHistory>${MAX_HISTORY}MaxHistory>
            
            <timeBasedFileNamingAndTriggeringPolicy
                    class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
                <maxFileSize>${MAX_FILE_SIZE}maxFileSize>
            timeBasedFileNamingAndTriggeringPolicy>
        rollingPolicy>
        <append>trueappend>
        <encoder>
            <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS}|%level|%t|%line|%-40.40logger{39}:%m%npattern>
            <charset>utf-8charset>
        encoder>
        <filter class="ch.qos.logback.classic.filter.LevelFilter">
            <level>DEBUGlevel>
            <onMatch>ACCEPTonMatch>
            <onMismatch>DENYonMismatch>
        filter>
    appender>
    <root level="${LOG_LEVEL}">
        <appender-ref ref="STDOUT"/>
        <appender-ref ref="info"/>
        <appender-ref ref="error"/>
        <appender-ref ref="warn"/>
        <appender-ref ref="debug"/>
    root>
    <logger name="com.common.log.bizerr.BizerrLog" level="OFF"/>
    <logger name="org.springframework" level="ERROR"/>
    <logger name="org.apache" level="ERROR"/>
    <logger name="net.sf" level="ERROR"/>
    <logger name="com.alibaba" level="ERROR"/>
    <logger name="org.quartz" level="ERROR"/>
    <logger name="com.mchange" level="ERROR"/>
    <logger name="springfox.documentation" level="ERROR"/>
    <logger name="org.thymeleaf" level="ERROR"/>
    <logger name="org.hibernate" level="ERROR"/>
    <logger name="org.apache.catalina.session.StandardManager" level="OFF"/>
    <logger name="com.common.log.bizerr.BizerrLog" level="debug"/>
    <logger name="com.api.common.AbstractRpcFilter" level="debug" />
    <logger name="com.dao.mapper" level="ERROR"/>
configuration>

方式2:


<configuration scan="false" scanPeriod="60 seconds" debug="false">
    <property name="encoder_pattern"
              value="%d{yyyy/MM/dd HH:mm:ss.SSS} %-5level [%thread] [equipment-maintenance-operation-service] [%X{traceId}] [%c{0}:%L] : %msg%n"/>
    <property name="LOG_PATH"
              value="/opt/logs/equipment-maintenance-operation-service"/>
    <property name="json_encoder_pattern"
              value='{
                "time": "%d{yyyy/MM/dd HH:mm:ss.SSS}",
                "level": "%5level",
                "thread": "%thread",
                "business": "mobile-boh-manager",
                "traceId": "%X{traceId:-}",
                "thread": "%thread",
                "class": "%c{0}:%L",
                "message": "%message",
                "stack_trace":"%exception{10}"
             }'/>

    <property name="maxHistory" value="60"/>

    <property name="maxFileSize" value="100MB"/>

    <property name="totalSizeCap" value="10GB"/>
    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>${encoder_pattern}pattern>
            <charset>UTF-8charset>
        encoder>
    appender>

    <appender name="FILE_All" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${LOG_PATH:-.}/level_all.logfile>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <fileNamePattern>${LOG_PATH:-.}/level_all.%d.%i.logfileNamePattern>
            <maxHistory>${maxHistory}maxHistory>
            <timeBasedFileNamingAndTriggeringPolicy
                    class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
                <maxFileSize>${maxFileSize}maxFileSize>
            timeBasedFileNamingAndTriggeringPolicy>
            
            <totalSizeCap>${totalSizeCap}totalSizeCap>
        rollingPolicy>
        <encoder>
            <pattern>${encoder_pattern}pattern>
            <charset>UTF-8charset>
        encoder>
    appender>

    <appender name="FILE_ERROR" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${LOG_PATH:-.}/level_error.logfile>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <fileNamePattern>${LOG_PATH:-.}/level_error.%d.%i.logfileNamePattern>
            <maxHistory>${maxHistory}maxHistory>
            <timeBasedFileNamingAndTriggeringPolicy
                    class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
                <maxFileSize>${maxFileSize}maxFileSize>`
            timeBasedFileNamingAndTriggeringPolicy>
            
            <totalSizeCap>${totalSizeCap}totalSizeCap>
        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>


    
    <root level="INFO">
        <appender-ref ref="STDOUT"/>
        <appender-ref ref="FILE_All"/>
        <appender-ref ref="FILE_ERROR"/>
    root>
    <logger name="org.mariadb.jdbc" level="DEBUG" additivity="false">
        <appender-ref ref="STDOUT"/>
    logger>


    

configuration>

nacos配置:

logging:
  config: http://${spring.cloud.nacos.config.server-addr}/nacos/v1/cs/configs?tenant=${spring.cloud.nacos.config.namespace}&group=DEFAULT_GROUP&dataId=logback-spring.xml

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