logback.xml配置样例


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

    
    <include resource="org/springframework/boot/logging/logback/defaults.xml"/>

    
    <property name="spring.application.name" value="springboot-demo" />
    <property name="logging.maxFileSize" value="10MB" />
    <property name="logging.maxHistory" value="60" />
    <property name="logging.totalSizeCap" value="20GB" />
    <property name="logging.path" value="../logs" />
    <property name="logging.pattern.file" value="${FILE_LOG_PATTERN}" />
    <property name="logging.pattern.console" value="${CONSOLE_LOG_PATTERN}" />

    
    <contextName>${spring.application.name}contextName>

    
    
    <appender name="error-file" class="ch.qos.logback.core.rolling.RollingFileAppender">
        
        <file>${logging.path}/${spring.application.name}/log_error.logfile>
        
        <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
            
            <fileNamePattern>${logging.path}/${spring.application.name}/error/log-error-%d{yyyy-MM-dd-HH}.%i.log
            fileNamePattern>
            
            <maxFileSize>${logging.maxFileSize}maxFileSize>
            
            <maxHistory>${logging.maxHistory}maxHistory>
            <totalSizeCap>${logging.totalSizeCap}totalSizeCap>
        rollingPolicy>
        
        <append>trueappend>
        
        <prudent>falseprudent>>
        <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
            <pattern>${logging.pattern.file}pattern>
            <charset>utf-8charset>
        encoder>
        
        <filter class="ch.qos.logback.classic.filter.LevelFilter">
            <level>errorlevel>
            <onMatch>ACCEPTonMatch>
            <onMismatch>DENYonMismatch>
        filter>
    appender>

    <appender name="file" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${logging.path}/${spring.application.name}/all.logfile>
        <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
            <fileNamePattern>${logging.path}/${spring.application.name}/all/log-all-%d{yyyy-MM-dd-HH}.%i.log
            fileNamePattern>
            <maxFileSize>${logging.maxFileSize}maxFileSize>
            <maxHistory>${logging.maxHistory}maxHistory>
            <totalSizeCap>${logging.totalSizeCap}totalSizeCap>
        rollingPolicy>
        <append>trueappend>
        <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
            <pattern>${logging.pattern.file}pattern>
            <charset>utf-8charset>
        encoder>
    appender>

    
    <appender name="console" class="ch.qos.logback.core.ConsoleAppender">
        
        <encoder>
            <pattern>${logging.pattern.console}pattern>
        encoder>
    appender>

    
    <logger name="springfox.documentation.spring.web" level="warn"/>

    
    <root level="INFO">
        <appender-ref ref="error-file"/>
        <appender-ref ref="file"/>
        <appender-ref ref="console"/>
    root>

configuration>

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