2018年3月7日 | Leave a comment https://www.jianshu.com/p/44154e96608b <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE configuration> <configuration> <!-- properties --> <property name="logDir" value="logs" /> <property name="maxHistory" value="30" /> <!-- 控制台输出 ConsoleAppender --> <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> <layout class="ch.qos.logback.classic.PatternLayout"> <Pattern> <!-- %replace: 字符串替换; %caller: 方法调用栈. --> <!-- (\bCaller.+?(?=\()): 正则, 匹配字符串"Caller...(",不含(号 --> %d{HH:mm:ss.SSS} %-5level %replace(%caller{1}){'(\bCaller.+?(?=\())|\r|\n|\s*|\t', ''} - %msg [%thread] %n </Pattern> </layout> </appender> <!-- 滚动文件输出, RollingFileAppender --> <appender name="DEBUG" class="ch.qos.logback.core.rolling.RollingFileAppender"> <!-- 日志过滤器 LevelFilter --> <filter class="ch.qos.logback.classic.filter.LevelFilter"> <level>DEBUG</level> <onMatch>ACCEPT</onMatch> <onMismatch>DENY</onMismatch> <!-- 只写入DEBUG级别的日志信息 --> </filter> <!-- 滚动策略 --> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <!-- 以天为单位记录日志, 只保留30天 --> <fileNamePattern>${logDir}/%d{yyyy-MM-dd}/debug-log.log</fileNamePattern> <maxHistory>${maxHistory}</maxHistory> </rollingPolicy> <encoder> <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern> </encoder> </appender> <appender name="WARN" class="ch.qos.logback.core.rolling.RollingFileAppender"> <!-- 日志过滤器 ThresholdFilter --> <filter class="ch.qos.logback.classic.filter.ThresholdFilter"> <!-- 只记录WARN及以上级别的日志. 即WARN, ERROR. --> <level>WARN</level> </filter> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <fileNamePattern>${logDir}/%d{yyyy-MM-dd}/warn-log.log</fileNamePattern> <maxHistory>${maxHistory}</maxHistory> </rollingPolicy> <encoder> <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern> </encoder> </appender> <!-- 邮件日志 <appender name="EMAIL" class="ch.qos.logback.classic.net.SMTPAppender"> <smtpHost>smtp.host.com</smtpHost> <smtpPort></smtpPort> <SSL>true</SSL> <username>your@mail.com</username> <password>yourPassword</password> <to>someone@mail.com</to> <to>another@mail.com</to> <from>your@mail.com/from> <layout class="ch.qos.logback.classic.PatternLayout"> <pattern>%date %-5level %logger{36} - %message%n</pattern> </layout> </appender> --> <!-- root, 只有在level及以上级别的日志会被输出 --> <!-- 例如: 当root level设置为INFO时, appender DEBUG中无法获取到DEBUG级别的日志事件, 则DEBUG日志信息也不会写入debug.log中. --> <root level="DEBUG"> <appender-ref ref="STDOUT" /> <appender-ref ref="DEBUG" /> <appender-ref ref="WARN" /> </root> </configuration> 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 <?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE configuration><configuration> <!-- properties --> <property name="logDir" value="logs" /> <property name="maxHistory" value="30" /> <!-- 控制台输出 ConsoleAppender --> <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> <layout class="ch.qos.logback.classic.PatternLayout"> <Pattern> <!-- %replace: 字符串替换; %caller: 方法调用栈. --> <!-- (\bCaller.+?(?=\()): 正则, 匹配字符串"Caller...(",不含(号 --> %d{HH:mm:ss.SSS} %-5level %replace(%caller{1}){'(\bCaller.+?(?=\())|\r|\n|\s*|\t', ''} - %msg [%thread] %n </Pattern> </layout> </appender> <!-- 滚动文件输出, RollingFileAppender --> <appender name="DEBUG" class="ch.qos.logback.core.rolling.RollingFileAppender"> <!-- 日志过滤器 LevelFilter --> <filter class="ch.qos.logback.classic.filter.LevelFilter"> <level>DEBUG</level> <onMatch>ACCEPT</onMatch> <onMismatch>DENY</onMismatch> <!-- 只写入DEBUG级别的日志信息 --> </filter> <!-- 滚动策略 --> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <!-- 以天为单位记录日志, 只保留30天 --> <fileNamePattern>${logDir}/%d{yyyy-MM-dd}/debug-log.log</fileNamePattern> <maxHistory>${maxHistory}</maxHistory> </rollingPolicy> <encoder> <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern> </encoder> </appender> <appender name="WARN" class="ch.qos.logback.core.rolling.RollingFileAppender"> <!-- 日志过滤器 ThresholdFilter --> <filter class="ch.qos.logback.classic.filter.ThresholdFilter"> <!-- 只记录WARN及以上级别的日志. 即WARN, ERROR. --> <level>WARN</level> </filter> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <fileNamePattern>${logDir}/%d{yyyy-MM-dd}/warn-log.log</fileNamePattern> <maxHistory>${maxHistory}</maxHistory> </rollingPolicy> <encoder> <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern> </encoder> </appender> <!-- 邮件日志 <appender name="EMAIL" class="ch.qos.logback.classic.net.SMTPAppender"> <smtpHost>smtp.host.com</smtpHost> <smtpPort></smtpPort> <SSL>true</SSL> <username>your@mail.com</username> <password>yourPassword</password> <to>someone@mail.com</to> <to>another@mail.com</to> <from>your@mail.com/from> <layout class="ch.qos.logback.classic.PatternLayout"> <pattern>%date %-5level %logger{36} - %message%n</pattern> </layout> </appender> --> <!-- root, 只有在level及以上级别的日志会被输出 --> <!-- 例如: 当root level设置为INFO时, appender DEBUG中无法获取到DEBUG级别的日志事件, 则DEBUG日志信息也不会写入debug.log中. --> <root level="DEBUG"> <appender-ref ref="STDOUT" /> <appender-ref ref="DEBUG" /> <appender-ref ref="WARN" /> </root> </configuration>