0

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?

Community
  • 1
  • 1
  • **Note** I previously tried with daily rolling frequency. That time also getting same issue. ```logger.rollingFrequency = 24 * 60 * 60``` – Anjan Majumder Feb 19 '20 at 07:14

1 Answers1

0

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)
Jayesh Patel
  • 938
  • 5
  • 16
  • Tried that too. That one is also not working. Thus I disabled daily rolling, so that atleast we get more logs from last log file. – Anjan Majumder Feb 19 '20 at 07:05
  • so you disable rolling due to time by setting `rollingFrequency` -1 that's why rolling is now based on `maximumFileSize`, so increase the file size to maximum. – Jayesh Patel Feb 19 '20 at 07:15
  • Right. But the problem is, I didn't getting old log files. I should get max 7 (```maximumNumberOfLogFiles = 7```) last log files from log directory. But only getting current day created log files. – Anjan Majumder Feb 19 '20 at 07:18