Details
-
Bug
-
Resolution: Not a bug
-
Critical
-
1.1.1
-
Java 1.8.0
Intellij idea
Spring-boot
logback-core
Description
I debug the logback codes and found the afterLastSlash function may caused NullPointException . Because of the function as follows.
public static String afterLastSlash(String sregex) {
int i = sregex.lastIndexOf('/');
if (i == -1) {
return sregex;
} else {
return sregex.substring(i + 1);
}
}
if the "sregex" is a null String . The function will throw the exception and the program logic will be interrupted .
I will show your this case how to happed .
I create the a spring-boot project use the logback as log framework . The logback configuration is
<?xml version="1.0" encoding="UTF-8"?> <configuration debug="false"> <property name="LOG_HOME" value="log" /> <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder"> <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern> </encoder> </appender> <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <FileNamePattern>${LOG_HOME}/connectivi.log.%d{yyyy-MM-dd}.log</FileNamePattern> <MaxHistory>6</MaxHistory> </rollingPolicy> <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder"> <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern> <immediateFlush>true</immediateFlush> </encoder> <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy"> <MaxFileSize>10MB</MaxFileSize> </triggeringPolicy> <filter class="ch.qos.logback.classic.filter.ThresholdFilter"> <level>TRACE</level> </filter> </appender> <logger name="com.mindsphere.china.poc.connectivity" level="DEBUG" additivity="false"> <appender-ref ref="STDOUT" /> <appender-ref ref="FILE" /> </logger> <root level="ERROR"> <appender-ref ref="STDOUT" /> <appender-ref ref="FILE" /> </root> </configuration>
The program write the log into the file until the file size is small than 10MB ,When the log file size is more than 10MB . The logback continue write log will trigger the SizeBasedTriggeringPolicy . The TimeBasedRollingPolicy class will call the rollover() function .
public void rollover() throws RolloverFailure {
// when rollover is called the elapsed period's file has
// been already closed. This is a working assumption of this method.
String elapsedPeriodsFileName = timeBasedFileNamingAndTriggeringPolicy.getElapsedPeriodsFileName();
String elapsedPeriodStem = FileFilterUtil.afterLastSlash(elapsedPeriodsFileName);
but the function timeBasedFileNamingAndTriggeringPolicy.getElapsedPeriodsFileName() return null . So the program could be broken and lose the logs.
BTW
I have choose another way to configuration the logback.xml and get the right result .But I think this is still a issues .So if you still want to have more details can connect will me by emails jbjiangbiao@icloud.com
Attachments
Issue Links
- relates to (out)
-
LOGBACK-1767 In RollingAppender, setting a triggering policy a second time will cause errors
- Resolved