Cocoalumberjack: After the new version 3.6.2 the default timezone is set to UTC. Need a method to set local time zone from DDLogFileManagerDefault

Created on 5 Aug 2020  路  1Comment  路  Source: CocoaLumberjack/CocoaLumberjack

New Issue Checklist

Issue Info

Info | Value |
-------------------------|-------------------------------------|
Platform Name | ios
Platform Version | 11.0
CocoaLumberjack Version | 3.6.2
Integration Method | cocoapods
Xcode Version | Xcode 11.6
Repro rate | 100%

Issue Description and Steps

After the new version 3.6.2 the default timezone is set to UTC. How can I update the timezone to local time?
I am using the below code to initialize DDlogger in my code.

DDLogFileManagerDefault *fileManager = [[DDLogFileManagerDefault alloc] initWithLogsDirectory:[self fileLoggerFilesDirectory]];
        [fileManager setMaximumNumberOfLogFiles:7];                     //Max 7 files.
        self.fileLogger = [[DDFileLogger alloc] initWithLogFileManager:fileManager];
        [self.fileLogger setMaximumFileSize:(1024 * 1024 * 2)];         //2 MB file max
        [self.fileLogger setRollingFrequency:(60.0f * 60.0f * 24.0f)];  //1 Day
        [DDLog addLogger:self.fileLogger withLevel:DDLogLevelDebug];

Most helpful comment

@shikhilnuwal You'd need to set the logFormatter of the fileLogger yourself. To restore the pre-3.6.2 behavior, use the following code:

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setFormatterBehavior:NSDateFormatterBehavior10_4];
[dateFormatter setDateFormat:@"yyyy/MM/dd HH:mm:ss:SSS"];
self.fileLogger.logFormatter = [[DDLogFileFormatterDefault alloc] initWithDateFormatter:dateFormatter];

Of course you can also implement your own log formatter, or further adjust the dateFormatter.

>All comments

@shikhilnuwal You'd need to set the logFormatter of the fileLogger yourself. To restore the pre-3.6.2 behavior, use the following code:

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setFormatterBehavior:NSDateFormatterBehavior10_4];
[dateFormatter setDateFormat:@"yyyy/MM/dd HH:mm:ss:SSS"];
self.fileLogger.logFormatter = [[DDLogFileFormatterDefault alloc] initWithDateFormatter:dateFormatter];

Of course you can also implement your own log formatter, or further adjust the dateFormatter.

Was this page helpful?
0 / 5 - 0 ratings