[Bug 92] New: TimeBasedRollingPolicy will not rollover a log file, append logs to a old log file.

http://bugzilla.qos.ch/show_bug.cgi?id=92 Summary: TimeBasedRollingPolicy will not rollover a log file, append logs to a old log file. Product: logback-core Version: unspecified Platform: All OS/Version: All Status: NEW Severity: critical Priority: P1 Component: Rolling AssignedTo: logback-dev@qos.ch ReportedBy: benbrand@mac.com If you use TimeBasedRollingPolicy to rollover a log file and no log wasn't wrote into the log beyond the timing of rollover, and if you restart your application, the log file doesn't roll, then new log will be appended into old log file. EVIDENCE: 1. in logback.xml, set your FileNamePattern like 'log.%d{yyyy-MM-dd_HH-mm}.log'. 2. Simply do a kind of thing, which will make some logs into your log file. 3. Wait for some minutes. 4. restart your application. 5. do a kind of thing, which will make some logs into your log file. the FileNamePattern is 'log.%d{yyyy-MM-dd_HH-mm}.log', so the log file will be roll every minutes. On case 5 of above example, the log file should be roll over, because some minutes already have passed after last logs wrote into the log file. But the file didn't be roll overed. THE CAUSE: In start() method of TimeBasedRollingPolicy, you initialize a variable 'lastCheck' to System.currentTimeStamp(). So if you restart your application, the last check time will be set to just NOW. you should initialize the variable to a last modified time of a current log file. See below source code. from '//modified by Tsutomu YANO' to '//until here'. SOURCE: public void start() { // set the LR for our utility object util.setContext(this.context); compress.setContext(this.context); // find out period from the filename pattern if (fileNamePatternStr != null) { fileNamePattern = new FileNamePattern(fileNamePatternStr, this.context); determineCompressionMode(); } else { addWarn(FNP_NOT_SET); addWarn(SEE_FNP_NOT_SET); throw new IllegalStateException(FNP_NOT_SET + SEE_FNP_NOT_SET); } DateTokenConverter dtc = fileNamePattern.getDateTokenConverter(); if (dtc == null) { throw new IllegalStateException("FileNamePattern [" + fileNamePattern.getPattern() + "] does not contain a valid DateToken"); } int len = fileNamePatternStr.length(); switch (compressionMode) { case Compress.GZ: activeFileNamePattern = new FileNamePattern(fileNamePatternStr.substring(0, len - 3), this.context); break; case Compress.ZIP: activeFileNamePattern = new FileNamePattern(fileNamePatternStr.substring(0, len - 4), this.context); break; case Compress.NONE: activeFileNamePattern = fileNamePattern; } addInfo("Will use the pattern " + activeFileNamePattern + " for the active file"); rc = new RollingCalendar(); rc.init(dtc.getDatePattern()); addInfo("The date pattern is '" + dtc.getDatePattern() + "' from file name pattern '" + fileNamePattern.getPattern() + "'."); rc.printPeriodicity(this); //modified by Tsutomu YANO //if a current log file exists, initialize a 'lastCheck' variable to the //last modified date of the file. File currentFile = new File(getParentFileName()); if(currentFile.exists() && currentFile.canRead()) { lastCheck.setTime(currentFile.lastModified()); } else { // currentTime = System.currentTimeMillis(); lastCheck.setTime(getCurrentTime()); } //until here nextCheck = rc.getNextCheckMillis(lastCheck); // Date nc = new Date(); // nc.setTime(nextCheck); } -- Configure bugmail: http://bugzilla.qos.ch/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- You are the assignee for the bug, or are watching the assignee.

http://bugzilla.qos.ch/show_bug.cgi?id=92 benbrand@mac.com changed: What |Removed |Added ---------------------------------------------------------------------------- Summary|TimeBasedRollingPolicy will |TimeBasedRollingPolicy |not rollover a log file, |append logs into a old log |append logs to a old log |file, instead of rolling the |file. |log file. -- Configure bugmail: http://bugzilla.qos.ch/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- You are the assignee for the bug, or are watching the assignee.

http://bugzilla.qos.ch/show_bug.cgi?id=92 manhole@max.hi-ho.ne.jp changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |manhole@max.hi-ho.ne.jp ------- Comment #1 from manhole@max.hi-ho.ne.jp 2008-05-13 13:27 ------- +1 -- Configure bugmail: http://bugzilla.qos.ch/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- You are the assignee for the bug, or are watching the assignee.
participants (1)
-
bugzilla-daemon@pixie.qos.ch