CocoaLumberjack - Swift : Not getting Previous Days Log Files

738 Views Asked by At

I am using CocoaLumberjack/Swift Pod in my iOS project.

The problem is, I am getting always Current day(Today or Last day of last time app launched) log files. CocoaLumberjack doesn't keeping old log files of Previous days.

For me Today is 2020-02-19. And the files I get from CocoaLumberjack:

xyz 2020-02-19--05-55-39-774.log // file size -> 10 MB

xyz 2020-02-19--05-55-46-305.log // file size -> 1.7 MB

** There are no older files from previous days

I disabled Time Based Rolling.

logger.rollingFrequency = -1 // also tried with 0

And Use 10 MB memory limit for each file

logger.maximumFileSize = 10 * (1024 * 1024) //10MB

According the CocoaLumberjack document.

* You may optionally disable rolling due to filesize by setting `maximumFileSize` to zero.
* If you do so, rolling is based solely on `rollingFrequency`.

Here is my source code from AppDelegate.

import CocoaLumberjack

...... 

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    // Enable CocoaLumberjack logging
    self.setLoggingProperty()
}

private func setLoggingProperty() {
    if #available(iOS 10.0, *) {
        DDLog.add(DDOSLogger.sharedInstance)
    } else {
        // Fallback on earlier versions
        DDLog.add(DDASLLogger.sharedInstance)
        if let dDTTYLogger = DDTTYLogger.sharedInstance {
            DDLog.add(dDTTYLogger)
        }
    }

    let logger: DDFileLogger = DDFileLogger.init()

    logger.maximumFileSize = 10 * (1024*1024) //10MB
    logger.rollingFrequency = -1 // Disable time base rolling

    logger.logFileManager.maximumNumberOfLogFiles = 7
    DDLog.add(logger)
}

Does anyone faces similar issue? Am I missing something?

1

There are 1 best solutions below

3
Jayesh Patel On

change the rolling frequency and size. Sets the bellow snippet

let fileLogger = DDFileLogger(logFileManager: LogsManager.shared())
        DDLog.add(DDOSLogger.sharedInstance)
        // 24-hour rolling, maximum 14 files, max 50 MB per file.
        fileLogger.rollingFrequency = 60 * 60 * 24
        fileLogger.maximumFileSize = 50 * 1024 * 1024;
        fileLogger.logFileManager.maximumNumberOfLogFiles = 14;
        // The file logger
        DDLog.add(fileLogger)
        // TTY = The Xcode console logger
        DDLog.add(DDTTYLogger.sharedInstance)
        // ASL = The Apple System Logs
        DDLog.add(DDOSLogger.sharedInstance)