Log rolling not working?

556 views
Skip to first unread message

Paul

unread,
Apr 18, 2014, 10:37:14 AM4/18/14
to cocoalu...@googlegroups.com
Hello,

I can't seem to get my log files to roll.  I thought perhaps it was how I implemented it, so I tried the included sample project " RollingTestMac"  but this doesn't seem to work either.
The code is below. I presume from this I should see 4 log files in the logsDirectory after a few minutes? The app runs for 10 minutes and there's only one file. Even if I force a roll with
rollLogFileWithCompletionBlock  I still only have one file.  Am I missing something or is there a bug?   I'm using commit  01ad86d6c3   with Xcode 5.1.1on MacOSX 10.8.5


    fileLogger = [[DDFileLogger alloc] init];   
    fileLogger.maximumFileSize = 1024 * 1;  //  1 KB
    fileLogger.rollingFrequency = 60;       // 60 Seconds
    fileLogger.logFileManager.maximumNumberOfLogFiles = 4;
     [DDLog addLogger:fileLogger];
    NSLog(@"Logging to: %@", [fileLogger.logFileManager logsDirectory]);


Thanks
Paul

Neil Tiffin

unread,
Apr 18, 2014, 1:33:44 PM4/18/14
to cocoalu...@googlegroups.com
My guess is that you need to write something to the logs it order for it to show up in the rolled logs, which work fine here.

One line is only going to show in 1 log file regardless, so try a loop on the NSLog statement logging every 15 seconds for 4 minutes and see if it does not work.

Neil

--
You received this message because you are subscribed to the Google Groups "CocoaLumberjack" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cocoalumberja...@googlegroups.com.
To post to this group, send email to cocoalu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cocoalumberjack/86f37c4f-3c4f-4755-b5c7-9218bbec4d8d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Paul

unread,
Apr 18, 2014, 3:54:08 PM4/18/14
to cocoalu...@googlegroups.com
Thanks for the reply Neil. The logs are being appended to every second. See the sample code for the app  "Rolling Test Mac" which comes with CocoaLumberjack.
I think it must be a bug if the sample demo app is not working.


#import "RollingTestMacAppDelegate.h"

#import "DDLog.h"
#import "DDFileLogger.h"

// Debug levels: off, error, warn, info, verbose
static const int ddLogLevel = LOG_LEVEL_VERBOSE;


@implementation RollingTestMacAppDelegate

@synthesize window;

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{

    fileLogger = [[DDFileLogger alloc] init];
   
    fileLogger.maximumFileSize = 1024 * 1;  //  1 KB
    fileLogger.rollingFrequency = 60;       // 60 Seconds
   
    fileLogger.logFileManager.maximumNumberOfLogFiles = 4;
   
    [DDLog addLogger:fileLogger];
   
    // Test auto log file roll
   
    [NSTimer scheduledTimerWithTimeInterval:1.0
                                     target:self
                                   selector:@selector(fillLogFiles:)
                                   userInfo:nil
                                    repeats:YES];
   
    // Test forced log file roll
   
//  DDLogInfo(@"Log file 1 : Log message 1");
//  DDLogInfo(@"Log file 1 : Log message 2");
//  DDLogInfo(@"Log file 1 : Log message 3");
// 
//  [fileLogger rollLogFile];
// 
//  DDLogInfo(@"Log file 2 : Log message 1");
//  DDLogInfo(@"Log file 2 : Log message 2");
//  DDLogInfo(@"Log file 2 : Log message 3");
}

- (void)fillLogFiles:(NSTimer *)aTimer
{
    int max = 1;
   
    // To test rolling log files due to age, set max to 1
    // To test rolling log files due to size, set max to 10
   
    for (int i = 0; i < max; i++)
    {
        DDLogInfo(@"I like cheese");
    }
   
    NSLog(@"Inc");
}

@end


Paul

unread,
Apr 18, 2014, 4:48:04 PM4/18/14
to cocoalu...@googlegroups.com

 Update:  this seems to be a bug in CocoaLumberjack version 1.8.1.
I tested release 1.7.0 and 1.8.0  and log rolling is working in those.

Bogdan Poplauschi

unread,
May 26, 2014, 2:27:33 AM5/26/14
to cocoalu...@googlegroups.com
Could you please retry this with the latest 1.9.0 version? There is an issue in rolling we fixed for 1.9.0 and another that it is not yet fixed. Just want to make sure which one it is.

Travis Bader

unread,
Jun 5, 2014, 5:07:54 PM6/5/14
to cocoalu...@googlegroups.com
I have the same issue and it is still happening in 1.9.0

Matt G

unread,
Jun 17, 2014, 4:28:39 AM6/17/14
to cocoalu...@googlegroups.com
This bug is in 1.9.0 and is related to this code in currentLogFileInfo:

            DDLogFileInfo *mostRecentLogFileInfo = [sortedLogFileInfos objectAtIndex:0];

            

            BOOL shouldArchiveMostRecent = NO;

            

            if (mostRecentLogFileInfo.isArchived)

            {

                shouldArchiveMostRecent = NO;

            }

........

            if (!_doNotReuseLogFiles && !shouldArchiveMostRecent)

            {

                NSLogVerbose(@"DDFileLogger: Resuming logging with file %@", mostRecentLogFileInfo.fileName);

                

                currentLogFileInfo = mostRecentLogFileInfo;

            }



So the problem is that if the most recent log file is already archived then the code sets  currentLogFileInfo to that file instead of falling down to the code lower down which creates a new log.

The simple solution is to :

            DDLogFileInfo *mostRecentLogFileInfo = [sortedLogFileInfos objectAtIndex:0];

            

            BOOL shouldArchiveMostRecent = NO;

            BOOL mostRecentIsArchived = mostRecentLogFileInfo.isArchived;

            if (mostRecentIsArchived)

            {

                shouldArchiveMostRecent = NO;

            }

........

            if (!_doNotReuseLogFiles && !shouldArchiveMostRecent && !mostRecentIsArchived)

            {

                NSLogVerbose(@"DDFileLogger: Resuming logging with file %@", mostRecentLogFileInfo.fileName);

                

                currentLogFileInfo = mostRecentLogFileInfo;

            }


Reply all
Reply to author
Forward
0 new messages