How to delete log file from saved location path.

714 views
Skip to first unread message

Subodh Kumar

unread,
Apr 23, 2014, 10:10:26 AM4/23/14
to cocoalu...@googlegroups.com
Hi,

I have integrated lumberjack framework in my application. I have changed the log file location i.e.. Document directory. I am using this code

NSFileManager *fileManager = [NSFileManager defaultManager];

NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

NSString *documentsDir = [documentPaths objectAtIndex:0];

    BOOL isDir=YES;

    if(![fileManager fileExistsAtPath:[documentsDir stringByAppendingPathComponent:@"LogFile"] isDirectory:&isDir]){

        if(![fileManager createDirectoryAtPath:[documentsDir stringByAppendingPathComponent:@"LogFile"] withIntermediateDirectories:YES attributes:nil error:nil])

            NSLog(@"Error: Create folder failed");

        



    }

    NSString *logFilePath = [documentsDir stringByAppendingPathComponent:[NSString stringWithFormat:@"LogFile"]];

    

    [DDLog addLogger:[DDASLLogger sharedInstance]];

    [DDLog addLogger:[DDTTYLogger sharedInstance]];

    

    DDLogFileManagerDefault *documentsFileManager = [[DDLogFileManagerDefault alloc]

                                                     initWithLogsDirectory:logFilePath];

    

    DDFileLogger *fileLogger = [[DDFileLogger alloc]

                                initWithLogFileManager:documentsFileManager];

    

    [fileLogger setMaximumFileSize:(1024 * 1)];

    [fileLogger setRollingFrequency:(3600.0 * 24.0)];  // roll everyday

    [[fileLogger logFileManager] setMaximumNumberOfLogFiles:5];

    [fileLogger setLogFormatter:[[DDLogFileFormatterDefault alloc]init]];

    

    [DDLog addLogger:fileLogger];



Now i want to remove oldest one log file if it created 5 log files. So if new one created then max no of log file will still 5.


Thanks

Paul

unread,
Apr 23, 2014, 6:08:48 PM4/23/14
to cocoalu...@googlegroups.com
Cocoalumberjack will automatically do this for you. Try setting the  rolling frequency to 60 seconds and you will see that over 5 minutes, you will get 5 files and after 10 mins, you will still only have 5 files.
However I have found the rolling the logs does work any more in version 1.8.1 so you need to use version 1.8.0 from github.

Paul

Subodh Kumar

unread,
Apr 24, 2014, 5:48:58 AM4/24/14
to cocoalu...@googlegroups.com, pa...@sparkleapps.com
Hi Paul,
Thanks for reply. I have downloaded 1.8.0 version. It is not working  as per my requirement. Even when i am trying to write more loges. It is creating more than 5 files and not deleting older one.. But i have to limit it unto 5.

Any suggestions.

Subodh

Subodh Kumar

unread,
Apr 24, 2014, 5:49:28 AM4/24/14
to cocoalu...@googlegroups.com

Bogdan Poplauschi

unread,
May 26, 2014, 2:34:28 AM5/26/14
to cocoalu...@googlegroups.com
Hi there,

Please retry this using the latest 1.9.0 release (fixed an issue with rolling). If the problem persists, please file an issue on https://github.com/CocoaLumberjack/CocoaLumberjack/issues
Reply all
Reply to author
Forward
0 new messages