The original log file is configured as follows:
<?XML version= "1.0" encoding= "UTF-8"?><ConfigurationScan= "true"Scanperiod= "Seconds"Debug= "false"> <Contextname>Logback</Contextname> <!--define the storage address of the log file do not use relative paths in Logback configuration - < Propertyname= "Log.path"value= "E:\\log\\logback.log" /> <!--Output to console - <Appendername= "Console"class= "Ch.qos.logback.core.ConsoleAppender"> <Filterclass= "Ch.qos.logback.classic.filter.ThresholdFilter"> < Level>INFO</ Level> </Filter> <Withjansi>True</Withjansi> <Encoder> <!--<pattern>%d%p (%file:%line\)-%m%n</pattern> - <!--formatted output:%d: Represents the date%thread: Indicates the thread name%-5level: The level shows 5 character widths from the left%msg: Log message%n: is a line break - <pattern>%black (console-)%red (%d{yyyy-mm-dd HH:mm:ss})%green ([%thread])%highlight (%-5level)%boldmagenta (%logger)-%cyan (%msg% N</pattern> <CharSet>UTF-8</CharSet> </Encoder> </Appender> <!--Output to File - <Appendername= "File"class= "Ch.qos.logback.core.rolling.RollingFileAppender"> <file>${log.path}</file> <Rollingpolicyclass= "Ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <Filenamepattern>Logback.%d{yyyy-mm-dd-hh-mm}.log</Filenamepattern> <maxhistory>30</maxhistory> <Totalsizecap>1GB</Totalsizecap> </Rollingpolicy> <Encoder> <!--formatted output:%d: Represents the date%thread: Indicates the thread name%-5level: The level shows 5 character widths from the left%msg: Log message%n: is a line break - <pattern>File records-%d{yyyy-mm-dd HH:MM:SS} [%thread]%-5level%logger{36}-%msg%n</pattern> <CharSet>GBK</CharSet> </Encoder> </Appender> <Root Level= "Info"> <Appender-refref= "Console" /> <Appender-refref= "File" /> </Root> <Loggername= "Com.sxd.controller"/> <Loggername= "Com.sxd.util.LogTestController" Level= "WARN"additivity= "false"> <Appender-refref= "Console" /> </Logger></Configuration>
View Code
But during the operation, it was found that
The generated log file is not split according to the date of the month and year in the configuration above.
Does not automatically clean up when you hit the maximum number of files,
is not generated to the specified log file directory, but is generated under the project root directory.
<?XML version= "1.0" encoding= "UTF-8"?><ConfigurationScan= "true"Scanperiod= "Seconds"Debug= "false"> <Contextname>Logback</Contextname> <!--define the storage address directory for log files - < Propertyname= "Log_home"value= "e:/log/"/> <!--Output to console - <Appendername= "Console"class= "Ch.qos.logback.core.ConsoleAppender"> <Filterclass= "Ch.qos.logback.classic.filter.ThresholdFilter"> < Level>INFO</ Level> </Filter> <Withjansi>True</Withjansi> <Encoder> <!--<pattern>%d%p (%file:%line\)-%m%n</pattern> - <!--formatted output:%d: Represents the date%thread: Indicates the thread name%-5level: The level shows 5 character widths from the left%msg: Log message%n: is a line break - <pattern>%black (console-)%red (%d{yyyy-mm-dd HH:mm:ss})%green ([%thread])%highlight (%-5level)%boldmagenta (%logger)-%cyan (%msg% N</pattern> <CharSet>UTF-8</CharSet> </Encoder> </Appender> <!--Output to File - <Appendername= "File"class= "Ch.qos.logback.core.rolling.RollingFileAppender"> <Rollingpolicyclass= "Ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy"> <Filenamepattern>${log_home}logback.%d{yyyy-mm-dd-hh-mm}[%i].log</Filenamepattern> <MaxFileSize>10kb</MaxFileSize> <maxhistory>30</maxhistory> <Totalsizecap>1GB</Totalsizecap> </Rollingpolicy> <Encoder> <!--formatted output:%d: Represents the date%thread: Indicates the thread name%-5level: The level shows 5 character widths from the left%msg: Log message%n: is a line break - <pattern>File records-%d{yyyy-mm-dd HH:MM:SS} [%thread]%-5level%logger-%msg%n</pattern> <CharSet>UTF-8</CharSet> </Encoder> </Appender> <Root Level= "Info"> <Appender-refref= "Console" /> <Appender-refref= "File" /> </Root> <Loggername= "Com.sxd.controller"/> <Loggername= "Com.sxd.util.LogTestController" Level= "WARN"additivity= "false"> <Appender-refref= "Console" /> </Logger></Configuration>
View Code
"Spring boot logback" Log logback generate log file under this project, not in the specified log file directory/specified log file reached the maximum value is not cut according to the configuration