Skip to content

Instantly share code, notes, and snippets.

@steipete
Created September 9, 2010 13:36
Show Gist options
  • Save steipete/571860 to your computer and use it in GitHub Desktop.
Save steipete/571860 to your computer and use it in GitHub Desktop.
//
// PSDDFormatter.h
// Created by Peter Steinberger on 08.09.10.
//
#import "DDLog.h"
@interface PSDDFormatter : NSObject <DDLogFormatter> {
NSDateFormatter *dateFormatter;
}
@end
//
// PSDDFormatter.m
// Created by Peter Steinberger on 08.09.10.
//
#import "PSDDFormatter.h"
@implementation PSDDFormatter
- (id)init {
if((self = [super init]))
{
dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setFormatterBehavior:NSDateFormatterBehavior10_4];
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss:SSS"];
}
return self;
}
- (NSString *)formatLogMessage:(DDLogMessage *)logMessage {
NSString *logLevel;
switch (logMessage->logFlag) {
case LOG_FLAG_ERROR : logLevel = @"Error: "; break;
case LOG_FLAG_WARN : logLevel = @"Warning: "; break;
case LOG_FLAG_INFO : logLevel = @""; break;
default : logLevel = @"V"; break;
}
NSString *dateAndTime = [dateFormatter stringFromDate:(logMessage->timestamp)];
NSString *logMsg = logMessage->logMsg;
return [NSString stringWithFormat:@"%@%@(%@) [%@ %@/%d] %@", logLevel, dateAndTime, [logMessage threadID], [logMessage fileName], [logMessage methodName], logMessage->lineNumber, logMsg];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment