I set the doNotReuseLogFiles to YES, and I hope the DDFileLogger create the new log file when I init the DDFileLogger. But before I release the DDFileLogger, I will get the currentLogFileInfo many times. I will get many infos!! I check the master branch:
- (DDLogFileInfo *)lt_currentLogFileInfo {
// Check if the file we've found is still valid. Otherwise create a new one.
if (newCurrentLogFile != nil && [self lt_shouldUseLogFile:newCurrentLogFile]) {
if (isResuming) {
NSLogVerbose(@"DDFileLogger: Resuming logging with file %@", newCurrentLogFile.fileName);
}
_currentLogFileInfo = newCurrentLogFile;
} else {
NSString *currentLogFilePath = [_logFileManager createNewLogFile];
_currentLogFileInfo = [[DDLogFileInfo alloc] initWithFilePath:currentLogFilePath];
}
}
- (BOOL)lt_shouldUseLogFile:(nonnull DDLogFileInfo *)logFileInfo {
NSAssert([self isOnInternalLoggerQueue], @"lt_ methods should be on logger queue.");
NSParameterAssert(logFileInfo);
if (logFileInfo.isArchived) { // Archived log files are no longer valid for use.
return NO;
}
if (_doNotReuseLogFiles || [self lt_shouldLogFileBeArchived:logFileInfo]) { // This log file needs to be archived. No longer valid.
logFileInfo.isArchived = YES;
NSString *archivedLogFilePath = [logFileInfo.fileName copy];
if ([_logFileManager respondsToSelector:@selector(didArchiveLogFile:)]) {
dispatch_async(_completionQueue, ^{
[self->_logFileManager didArchiveLogFile:archivedLogFilePath];
});
}
return NO;
}
// All checks have passed. It's valid.
return YES;
}
The [self lt_shouldUseLogFile:newCurrentLogFile] always be NO, because the _doNotReuseLogFiles is YES. So it will call createNewLogFile everytime!
I think that currentLogFileInfo should be a getter mathod, and it should not be a handler method! Right?
Thanks for reporting this.
We were simply missing a check whether we're currently resuming or not. Fixed in #1049, which also includes a test case that makes sure this won't happen again...
Do you have an estimation when 3.5.2 is going to be released?
While I can't give you any specific date right now, I want to release these current tip of master as 3.5.2.
Any thoughts? @CocoaLumberjack/collaborators
IMO we should release often. We have a lot of contributors, so any hot fix will show up soon as well.
Then I'll prepare for the release from now!
@rivera-ernesto @ffried @lolgear
Thanks for your help! I have just released CocoaLubmerjack 3.5.2 and registered it to CocoaPods.
@Whirlwind @vladiulianbogdan
Thanks for watting!
Could you try to use CocoaLumberjack 3.5.2?
https://github.com/CocoaLumberjack/CocoaLumberjack/releases/tag/3.5.2
It seems not work at 3.5.2.
@Whirlwind Can you reproduce the bug in a sample project you could attach to this issue? What's different than the setup in the test case I've added in this commit?
We face this issue, only when we are writing a runnig sessions's output log, but at the same time, we start a new session and touch the currentLogFileInfo getter. It will output a empty log file with nothing to output. Seems a race condition cause the issue ?
Maybe I need some demo code for this.
Most helpful comment
While I can't give you any specific date right now, I want to release these current tip of master as 3.5.2.
Any thoughts? @CocoaLumberjack/collaborators