Created
December 10, 2014 21:10
-
-
Save ddonovan/15b05523fd329b128b6e to your computer and use it in GitHub Desktop.
Snippet on adding logging to the app using Lumberjack.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Logging.h | |
// | |
#import <CocoaLumberjack/CocoaLumberjack.h> | |
// | |
//typedef NS_ENUM(NSUInteger, DDLogLevel) { | |
// DDLogLevelOff = 0, | |
// DDLogLevelError = (DDLogFlagError), // 0...00001 | |
// DDLogLevelWarning = (DDLogLevelError | DDLogFlagWarning), // 0...00011 | |
// DDLogLevelInfo = (DDLogLevelWarning | DDLogFlagInfo), // 0...00111 | |
// DDLogLevelDebug = (DDLogLevelInfo | DDLogFlagDebug), // 0...01111 | |
// DDLogLevelVerbose = (DDLogLevelDebug | DDLogFlagVerbose), // 0...11111 | |
// DDLogLevelAll = NSUIntegerMax // 1111....11111 (DDLogLevelVerbose plus any other flags) | |
//}; | |
static const DDLogLevel ddLogLevel = DDLogLevelVerbose; | |
// redefine NSLog so we don't have to go change all NSLog calls to Lumberjack. | |
#define NSLog DDLogVerbose | |
////////////////////////// | |
#import "AppDelegate.h" | |
#import <CocoaLumberjack/CocoaLumberjack.h> | |
@interface AppDelegate () | |
@end | |
@implementation AppDelegate | |
- (void)setupLogging{ | |
// configure lumberjack logging. | |
[DDLog addLogger:[DDASLLogger sharedInstance]]; | |
[DDLog addLogger:[DDTTYLogger sharedInstance]]; | |
DDFileLogger *fileLogger = [[DDFileLogger alloc] init]; | |
fileLogger.rollingFrequency = 60 * 60 * 24; // 24 hour rolling | |
[fileLogger setMaximumFileSize:1024 * 1024 *2]; // 2mb file | |
fileLogger.logFileManager.maximumNumberOfLogFiles = 7; // 7 days of logs. | |
[DDLog addLogger:fileLogger]; | |
DDLogVerbose(@"Lumberjack Logging Setup"); | |
} | |
- (void)setupUserDefaults{ | |
// configure our NSUserDefaults to use a plist file in our project. | |
NSURL *defaultPrefsFile = [[NSBundle mainBundle] | |
URLForResource:@"DefaultUserSettings" withExtension:@"plist"]; | |
NSDictionary *defaultPrefs =[NSDictionary dictionaryWithContentsOfURL:defaultPrefsFile]; | |
[[NSUserDefaults standardUserDefaults] registerDefaults:defaultPrefs]; | |
} | |
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { | |
[self setupUserDefaults]; | |
[self setupLogging]; | |
return YES; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment