1

I am using cocoa lumberjack to store my app logs. I want to roll the log file based on size only (if it reaches 1MB).

Below code i am using for configuration.

    let fileLogger: DDFileLogger = DDFileLogger()   
     fileLogger.rollingFrequency = -1
    fileLogger.maximumFileSize = 1024 * 1024
    fileLogger.logFileManager.maximumNumberOfLogFiles = 7
    DDLog.add(fileLogger

But i am facing one problem, it is creating new file on every time app launch instead of creating after reaching 1MB.

As of my analysis in DDFileLogger.m file under - (NSFileHandle *)lt_currentLogFileHandle method, _currentLogFileHandle property is alway nil on app launch.

is anything i am missing here. Please suggest me

I am using cocoaLumberjack 3.5.1 version. app supports from iOS 10 Xcode version 10.1

oguz ismail
  • 1
  • 16
  • 47
  • 69
Logger
  • 1,274
  • 1
  • 14
  • 25
  • I think you need to use the `initWithLogFileManager:` version to create the `DDFileLogger` instance with your own version of the file manager. See [this page](https://github.com/CocoaLumberjack/CocoaLumberjack/blob/master/Documentation/LogFileManagement.md). Alternatively write your own logger class which shouldn't take more than an hour. I've never been satisfied with anyone elses logging code. – trojanfoe Feb 26 '19 at 10:34
  • @trojanfoe. I did not get you. Can you please elaborate? – Logger Feb 26 '19 at 10:40
  • You have to create your own log file manager class in order to manage log file creation I believe. See the page I linked. – trojanfoe Feb 26 '19 at 10:41
  • what if you set maximumNumberOfLogFiles to 1 ? – Mosbah Feb 26 '19 at 13:12
  • this maybe helpful too: https://stackoverflow.com/questions/35991208/cocoalumberjack-log-to-one-file – Mosbah Feb 26 '19 at 13:14
  • @Mosbah if i set maximumNumberOfLogFiles to 1 on app launch it is deleting old file and creating new file. – Logger Feb 26 '19 at 14:54
  • Possible duplicate of [iOS CocoaLumberjack: New log file is creating on every time app launch, if backgroundModes enabled and app running in simulator](https://stackoverflow.com/questions/54919967/ios-cocoalumberjack-new-log-file-is-creating-on-every-time-app-launch-if-backg) – Parag Bafna Mar 26 '19 at 15:38
  • This was bug with CocoaLumberjack library. They released new version with fix. – Logger May 31 '19 at 05:46

0 Answers0