Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Introduction to CocoaLumberjack

Introduction to CocoaLumberjack

Presented at Cocoaheads Copenhagen on 13 Februrary 2014

Kristian Andersen

February 13, 2014
Tweet

More Decks by Kristian Andersen

Other Decks in Programming

Transcript

  1. Performance “[…] I switched out all the logging statements from

    using NSLog to use CocoaLumberjacks DDLog instead, and saw an increase in performance of almost 6x […]”
  2. Performance “[…] I switched out all the logging statements from

    using NSLog to use CocoaLumberjacks DDLog instead, and saw an increase in performance of almost 6x […]”
  3. Performance 1. Open a new connection to ASL daemon 2.

    Send message to ASL daemon 3. Close that connection 4. Write the same message to STDERR 5. for each NSLog statement: GOTO 1;
  4. LEVELS DDLogError(@"Some error %@, %@", error, error.userInfo); DDLogWarn(@"Unexpected thing"); DDLogInfo(@"Heads

    up here"); DDLogDebug(@"Bug bug debug"); DDLogVerbose(@"Extreme verbosity");
  5. Formatters DDLogError(@"Paper Jam!"); // E | Paper Jam! DDLogWarn(@"Low toner.");

    // W | Low toner. DDLogInfo(@"Doc printed."); // I | Doc printed. DDLogDebug(@"Debugging"); // D | Debugging DDLogVerbose(@"Init doc_parse"); // V | Init doc_parse.
  6. Formatters - (NSString *)formatLogMessage:(DDLogMessage *)logMessage { NSString *logLevel; switch (logMessage->logFlag)

    { case LOG_FLAG_ERROR : logLevel = @"E"; break; case LOG_FLAG_WARN : logLevel = @"W"; break; case LOG_FLAG_INFO : logLevel = @"I"; break; case LOG_FLAG_DEBUG : logLevel = @"D"; break; default : logLevel = @"V"; break; } return [NSString stringWithFormat:@"%@ | %@\n", logLevel, logMessage->logMsg]; }
  7. PER CLASS LEVEL + (NSArray *)registeredClasses; + (NSArray *)registeredClassNames; !

    + (int)logLevelForClass:(Class)aClass; + (int)logLevelForClassWithName:(NSString *)aClassName; ! + (void)setLogLevel:(int)logLevel forClass:(Class)aClass; + (void)setLogLevel:(int)logLevel forClassWithName:(NSString *)aClassName;
  8. Rolling Logs DDFileLogger *fileLogger = [[DDFileLogger alloc] init]; ! [fileLogger

    setRollingFrequency:60 * 60 * 24]; [fileLogger setMaximumFileSize:1024 * 1024 * 2]; [fileLogger.logFileManager setMaximumNumberOfLogFiles:7]; [DDLog addLogger:fileLogger];