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>
logback默认现在classpath中查找logback.groovy,找不到再找logback-test.xml,找不到再找logback.xml。Maven等工具打包时会忽略logback-test.xml,因此可以在classpath下同时放logback-test.xml和logback.xml,logback-test.xml用于开发,logback.xml用于生成环境。
上一篇: 至XX(直属领导)的一封信
下一篇: 下拉列表框的两种方式