First written logback-spring.xml file:
<? XML Version = "1.0" encoding = "UTF-. 8"?> <Configuration> <springProperty scope = "context" name = ". LOG_DIR" Source = "logback.path" /> <springProperty scope = "context" name = "the LEVEL" Source = "logback.level" /> <springProperty scope = "context" name = "APP_NAME" Source = "spring.application.name" /> <Property name = "FILE_LOG_PATTERN" value = "% DATE [Level% ] [thread%] [% File: Line%]%% n-MSG "/> ! <-% m output information,% p log level,% t thread name,% d date, full name of the class% c, % i increments from the digital index [0] ,,, -> <-! appender is a child node configuration is the component responsible for writing the log. -> <- the ConsoleAppender:! Log output to the console -> <name = the appender " <-! Console should use UTF-8, do not use the GBK, otherwise Chinese garbled -> <charset> UTF-8 </ charset> </ Encoder> </ appender> <- RollingFileAppender:! Scroll record file, first logging to the specified file, when a condition matches, logging to another file -> <- less probably means:! 1 the date of deposit log press, the date has changed, the front. the log file name of the day renamed to XXX% date% index, a new log is still demo.log -> <-! 2. If the date does not change, but the current log file is larger than 1KB, the current log dividing rename -> <the appender name = "fileServiceLog" class = "ch.qos.logback.core.rolling.RollingFileAppender"> <File>. LOG_DIR} {$ /} $ {APP_NAME .log </ File> <- rollingPolicy:! when scrolling occurs, determine the behavior of RollingFileAppender, to move and rename files. -> <- TimeBasedRollingPolicy:! The most common strategy rolling, rolling it to develop strategies based on time, responsible for both the scroll is also responsible for starting the scroll -> <rollingPolicy class = "ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> = "ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"> ! <- the maxFileSize:This is the size of the active file, the default value is 10MB, can be changed to see the effect 1KB test -> <! - the name of the active file will be based on the value fileNamePattern change from time to time once -> <- filename:! Log / demo.2017-12-05.0.log -> <fileNamePattern> $ {LOG_DIR } / {D% the MM-dd-YYYY} / {$ APP_NAME} - {D% the MM-dd-YYYY} (% I) .log </ fileNamePattern> <-! each generating a log file, the log file stored for 30 days -> <maxHistory> 30 </ maxHistory> <timeBasedFileNamingAndTriggeringPolicy class <the maxFileSize> 2000MB </ the maxFileSize> </ timeBasedFileNamingAndTriggeringPolicy> </ rollingPolicy> <Encoder> <-! pattern node, for setting the log input format -> <pattern> FILE_LOG_PATTERN $ {} </ pattern> <- coding logging:! Set here Character Set - -> <charset> UTF-. 8 </ charset> </ Encoder> <filter class = "ch.qos.logback.classic.filter.LevelFilter"> <Level> the LEVEL $ {} </ Level> <-! <onMatch> ACCEPT </ onMatch> -> <-! <onMismatch> DENY </ onMismatch> -> </ filter> </ the appender> <the appender name = "fileServiceLogError" class="ch.qos.logback.core.rolling.RollingFileAppender"> <File>. LOG_DIR} {$ / $ {APP_NAME -error.log} </ file> <- rollingPolicy:! when scrolling occurs, determine the behavior of RollingFileAppender, move and rename files involved. -> ! <- TimeBasedRollingPolicy: The most commonly used strategy rolling, rolling it to develop strategies based on time, responsible for both the scroll is also responsible for starting the scroll -> <! - the name of the active file will be based on the value fileNamePattern change from time to time once -> <- filename:! Log / demo.2017-12-05.0.log -> <fileNamePattern> $ {LOG_DIR } / {D% the MM-dd-YYYY} / {$ APP_NAME -error% D {} the MM-dd-YYYY} (% I) .log </ fileNamePattern>. <-! each generating a log file, the log file retention period is 30 days -> <maxHistory> 30 </ maxHistory> <timeBasedFileNamingAndTriggeringPolicy class = "ch.qos.logback.core.rolling. <-! pattern node, the log is used to set the input format -> <pattern>${FILE_LOG_PATTERN}</pattern> <- maxFileSize:! This is the size of the active file, the default value is 10MB, can be changed to see the effect of the test 1KB -> <maxFileSize> 50MB </ maxFileSize> </ timeBasedFileNamingAndTriggeringPolicy> </ rollingPolicy> <Encoder> <REF-REF = the appender "STDOUT" /> <! - log recording code: Here Character Set - -> <charset> UTF-. 8 </ charset> </ Encoder> <filter class = "ch.qos.logback.classic.filter.LevelFilter"> <level> ERROR </ level> <onMatch> ACCEPT </ onMatch> <onMismatch> DENY </ onMismatch> </ filter> </ appender> <-! console log level output -> <root level = "$ the LEVEL} { "> <REF-REF = the appender" fileServiceLog "/> <REF-REF = the appender" fileServiceLogError "/> </ the root> <Logger name =" org.springframework.amqp.rabbit.listener.BlockingQueueConsumer" level="OFF"/> <logger name="com.example" level="${LEVEL}"> <appender-ref ref="fileServiceLog" /> <appender-ref ref="fileServiceLogError" /> </logger> </configuration>
.Yml configuration file is:
#logback配置 logging: pattern: console: '%d -%msg%n' path: D:/data/log/seller.log level: debug