欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Java日志系统-logback配置

程序员文章站 2022-07-04 23:10:08
...

logback配置文件:logback.xml

<configuration debug="true" scan="true" scanPeriod="5 minutes">
    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n%rEx</pattern>
        </encoder>
    </appender>

    <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <fileNamePattern>logs/nexusy-api-%d{yyyy-MM-dd}.%i.gz</fileNamePattern>
            <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
                <maxFileSize>100MB</maxFileSize>
            </timeBasedFileNamingAndTriggeringPolicy>
            <maxHistory>30</maxHistory>
        </rollingPolicy>

        <encoder>
            <pattern>%d{HH:mm:ss.SSS} [%t] %-5p %c{36} - %m%n</pattern>
            <immediateFlush>false</immediateFlush>
            <outputPatternAsHeader>true</outputPatternAsHeader>
        </encoder>
    </appender>

    <logger name="com.nexusy.demo.api" level="DEBUG" additivity="false">
        <appender-ref ref="STDOUT"/>
        <appender-ref ref="FILE"/>
    </logger>

    <root level="DEBUG">
        <appender-ref ref="STDOUT"/>
        <appender-ref ref="FILE"/>
    </root>

</configuration>

 
Java日志系统-logback配置
            
    
    博客分类: Java logbackjavalog 
 logback默认现在classpath中查找logback.groovy,找不到再找logback-test.xml,找不到再找logback.xml。Maven等工具打包时会忽略logback-test.xml,因此可以在classpath下同时放logback-test.xml和logback.xml,logback-test.xml用于开发,logback.xml用于生成环境。

  • Java日志系统-logback配置
            
    
    博客分类: Java logbackjavalog 
  • 大小: 74.1 KB
相关标签: logback java log