http://tengj.top/2017/04/05/springboot7/
------------------
logback使用指南。
公司配置
<?xml version="1.0" encoding="UTF-8"?> <configuration scan="true" scanPeriod="5 seconds" debug="true"> <property resource="${profile.properties}/logback.properties" /> <appender name="stdoutAppender" class="ch.qos.logback.core.ConsoleAppender"> <filter class="ch.qos.logback.classic.filter.ThresholdFilter"> <level>${logback.stdoutLevel}</level> </filter> <!-- encoder 默认配置为PatternLayoutEncoder --> <encoder> <pattern>${logback.msg}</pattern> </encoder> </appender> <appender name="debugAppender" class="ch.qos.logback.core.rolling.RollingFileAppender"> <file>${logback.userHome}/${logback.fileName}_${logback.rootLevel}${logback.suffix}</file> <filter class="ch.qos.logback.classic.filter.ThresholdFilter"> <level>${logback.rootLevel}</level> </filter> <encoder> <pattern>${logback.msg}</pattern> </encoder> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <!-- rollover daily --> <fileNamePattern>${logback.userHome}/${logback.fileName}_${logback.rootLevel}_%d{${logback.datePattern}}.%i.log</fileNamePattern> <!-- keep ${logback.maxHistory} days' worth of history --> <maxHistory>${logback.maxHistory}</maxHistory> <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"> <!-- or whenever the file size reaches ${logback.maxFileSize} --> <maxFileSize>${logback.maxFileSize}</maxFileSize> </timeBasedFileNamingAndTriggeringPolicy> </rollingPolicy> </appender> <appender name="noticelog" class="ch.qos.logback.core.rolling.RollingFileAppender"> <File>${logback.userHome}/notice_${logback.rootLevel}.log</File> <filter class="ch.qos.logback.classic.filter.ThresholdFilter"> <level>${logback.rootLevel}</level> </filter> <encoder> <pattern>${logback.msg}</pattern> </encoder> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <FileNamePattern>${logback.userHome}/notice_${logback.rootLevel}_%d{${logback.datePattern}}.%i.log</FileNamePattern> <maxHistory>${logback.maxHistory}</maxHistory> <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"> <maxFileSize>${logback.maxFileSize}</maxFileSize> </timeBasedFileNamingAndTriggeringPolicy> </rollingPolicy> </appender> <logger name="NOTICE-LOG" additivity="false" level="debug"> <appender-ref ref="noticelog"/> <appender-ref ref="debugAppender" /> </logger> <logger name="org.apache.activemq" level="WARN" additivity="false"> <appender-ref ref="debugAppender" /> </logger> <logger name="org.apache.zookeeper" level="WARN" additivity="false"> <appender-ref ref="debugAppender"/> </logger> <!-- TRACE, DEBUG, INFO, WARN, ERROR, ALL 和 OFF --> <root level="${logback.rootLevel}"> <appender-ref ref="stdoutAppender" /> <appender-ref ref="debugAppender" /> </root> </configuration>
配置文件
logback.msg=%date [%thread] [%X{uid} - %X{url}] %-5level %logger{80} - %msg%nlogback.suffix=.loglogback.fileName=${project.artifactId}logback.userHome=./logs/${project.artifactId}#The date-and-time pattern, as found within the accolades of %d{} follow java.text.SimpleDateFormat conventionslogback.datePattern=yyyy-MM-dd#keep ${logback.maxHistory} 'logback.datePattern' worth of historylogback.maxHistory=30logback.maxFileSize=200MB#TRACE, DEBUG, INFO, WARN, ERROR, ALL, OFFlogback.stdoutLevel=debuglogback.rootLevel=debug
来源:https://www.cnblogs.com/pingh/p/8435208.html