Skip to content

Instantly share code, notes, and snippets.

@juliengrimault
Created March 17, 2012 03:33
Show Gist options
  • Save juliengrimault/2054724 to your computer and use it in GitHub Desktop.
Save juliengrimault/2054724 to your computer and use it in GitHub Desktop.
Cocoa Lumberjack formatter showing file, function and level of the log
//
// FileFunctionLevelFormatter.h
//
// Created by Julien Grimault on 23/1/12.
// Copyright (c) 2012 Julien Grimault. All rights reserved.
//
#import "DDLog.h"
@interface FileFunctionLevelFormatter : NSObject <DDLogFormatter>
@end
//
// FileFunctionLevelFormatter.m
//
// Created by Julien Grimault on 23/1/12.
// Copyright (c) 2012 Julien Grimault. All rights reserved.
//
#import "FileFunctionLevelFormatter.h"
@implementation FileFunctionLevelFormatter
- (NSString*)formatLogMessage:(DDLogMessage *)logMessage
{
NSString* logLevel = nil;
switch (logMessage->logLevel) {
case LOG_FLAG_ERROR : logLevel = @"E"; break;
case LOG_FLAG_WARN : logLevel = @"W"; break;
case LOG_FLAG_INFO : logLevel = @"I"; break;
default : logLevel = @"V"; break;
}
return [NSString stringWithFormat:@"[%@][%@ %@][Line %d] %@",
logLevel,
logMessage.fileName,
logMessage.methodName,
logMessage->lineNumber,
logMessage->logMsg];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment