美文网首页Spring
logback-spring.xml配置实例

logback-spring.xml配置实例

作者: 王勇1024 | 来源:发表于2018-12-31 22:29 被阅读12次
    <configuration>
        <logger name="org.springframework.web" level="INFO" />
    
        <!-- 注意这里一定要放到springProfile里, 否则在你本机执行的时候还是会去找相应的文件 -->
        <appender name="ROLLING_FILE"  class="ch.qos.logback.core.rolling.RollingFileAppender">
            <File>./logs/alpha.log</File>
            <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
                <!--日志文件输出的文件名-->
                <FileNamePattern>./logs/alpha.%d{yyyy-MM-dd}.log</FileNamePattern>
                <!--日志文件保留天数-->
                <maxHistory>10</maxHistory>
                <totalSizeCap>10GB</totalSizeCap>
            </rollingPolicy>
            <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
                <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern>
            </encoder>
        </appender>
    
        <appender name="ASYNC_FILE" class="ch.qos.logback.classic.AsyncAppender">
            <discardingThreshold>0</discardingThreshold>
            <queueSize>500</queueSize>
            <appender-ref ref="ROLLING_FILE" />
        </appender>
    
        <springProfile name="prod">
            <root level="INFO">
                <appender-ref ref="ASYNC_FILE" />
            </root>
        </springProfile>
    
        <springProfile name="dev">
            <root level="INFO">
                <appender-ref ref="ASYNC_FILE" />
            </root>
        </springProfile>
    
        <springProfile name="junit">
            <root level="INFO">
                <appender-ref ref="CONSOLE" />
            </root>
        </springProfile>
        <springProfile name="test">
            <root level="INFO">
                <appender-ref ref="CONSOLE" />
            </root>
        </springProfile>
    </configuration>
    

    相关文章

      网友评论

        本文标题:logback-spring.xml配置实例

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