最近用到logback配置文件,小小的了解了下,做一个笔记。供自己复习!
<?xml version="1.0" encoding="UTF-8"?> <configuration> <!-- 日志保存路径为tomcat下面的logs下面的user_center文件夹,logback会自动创建文件夹,这样设置了就可以输出日志文件了 --> <substitutionProperty name="logbase" value="${catalina.base}/logs/user_center/" /> <!--每个appender都是一个日志策略 --> <appender name="consoleAppender" class="ch.qos.logback.core.ConsoleAppender"> <layout class="ch.qos.logback.classic.PatternLayout"> <Pattern>.%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg %n </Pattern> </layout> <filter class="ch.qos.logback.classic.filter.ThresholdFilter"> <level>TRACE</level> </filter> </appender> <!-- 演示按时间滚动的策略 --> <appender name="dailyRollingFileAppender" class="ch.qos.logback.core.rolling.RollingFileAppender"> <File>${logbase}/usercenter.log</File> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <!-- daily rollover --> <FileNamePattern>${logbase}/usercenter.%d{yyyy-MM-dd}.log</FileNamePattern> <!-- 保留 30天数据,默认无限--> <maxHistory>30</maxHistory> </rollingPolicy> <encoder> <Pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{35} - %msg %n</Pattern> </encoder> </appender> <!-- 系统日志 --> <appender name="dailyRollingFileAppenderSys" class="ch.qos.logback.core.rolling.RollingFileAppender"> <File>${logbase}/sysusercenter.log</File> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <!-- daily rollover --> <FileNamePattern>${logbase}/sysusercenter.%d{yyyy-MM-dd}.log</FileNamePattern> <!-- 保留 30天数据,默认无限--> <maxHistory>30</maxHistory> </rollingPolicy> <encoder> <Pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{35} - %msg %n</Pattern> </encoder> </appender> <appender name="minuteRollingFileAppender" class="ch.qos.logback.core.rolling.RollingFileAppender"> <file>${logbase}/metrics.log</file> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <!-- rollover every minute --> <FileNamePattern>${logbase}/minute.%d{yyyy-MM-dd_HH-mm}.log</FileNamePattern> <!-- 最多保留10个文件,默认是7 --> <maxIndex>10</maxIndex> <!-- keep 30 minutes' worth of history --> <maxHistory>30</maxHistory> </rollingPolicy> <encoder> <Pattern>%-4relative [%thread] %-5level %logger{35} - %msg %n</Pattern> </encoder> </appender> <!-- 综合时间与大小的滚动策略,先按小时滚动,小时内的文件大于10mb时再按大小滚动 --> <appender name="businessLogFileAppender" class="ch.qos.logback.core.rolling.RollingFileAppender"> <file>${logbase}/business.log</file> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <fileNamePattern>${logbase}/business-%d{yyyy-MM-dd_HH}.%i.zip</fileNamePattern> <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"> <maxFileSize>200MB</maxFileSize> </timeBasedFileNamingAndTriggeringPolicy> </rollingPolicy> <encoder> <Pattern>%d{HH:mm:ss.SSS},%msg%n</Pattern> </encoder> </appender> <!--此处使用appender additivity是否继承父类的日志级别--> <logger name="com.kaiyuan.platform" level="DEBUG" additivity="false"> <appender-ref ref="dailyRollingFileAppender"/><appender-ref ref="consoleAppender" /> </logger> <!--根日志级别--> <root> <level value="DEBUG" /> <appender-ref ref="dailyRollingFileAppenderSys"/> </root> </configuration>原文链接:/xml/295136.html