Skip to content

Instantly share code, notes, and snippets.

@dtrenz
Created January 14, 2016 16:53
Show Gist options
  • Save dtrenz/ca730d9fff9cb6d9372c to your computer and use it in GitHub Desktop.
Save dtrenz/ca730d9fff9cb6d9372c to your computer and use it in GitHub Desktop.
Custom formatter for CocoaLumberjack to get XCGLogger (https://github.com/DaveWoodCom/XCGLogger) style log messages w/ log level, thread, file name, line #, & method name.
#import "DDLog.h"
@interface DTCustomFormatter : NSObject <DDLogFormatter>
@end
#import "DTCustomFormatter.h"
@implementation DTCustomFormatter
- (NSString *)formatLogMessage:(DDLogMessage *)logMessage {
NSString *levelStr;
switch (logMessage->_flag) {
case DDLogFlagError:
levelStr = @"Error";
break;
case DDLogFlagWarning:
levelStr = @"Warning";
break;
case DDLogFlagInfo:
levelStr = @"Info";
break;
case DDLogFlagDebug:
levelStr = @"Debug";
break;
default:
levelStr = @"Verbose";
break;
}
// Ex: "[Debug] [13469294] [DTAppDelegate:15] -[DTAppDelegate application:didFinishLaunchingWithOptions:] > Application launched"
return [NSString stringWithFormat:@"[%@] [%@] [%@:%lu] %@ > %@",
levelStr,
logMessage->_threadID,
logMessage->_fileName,
(unsigned long)logMessage->_line,
logMessage->_function,
logMessage->_message];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment