Global log level for CocoaLumberjack Global log level for CocoaLumberjack ios ios

Global log level for CocoaLumberjack


You could use an #include statement in your *.pch file so that it's automatically included in all your project's files.


I didn't find a better way to do it than the one explained in the article I mentioned in the question.

Constant.h

extern int const ddLogLevel;

Constant.m

#import "Constants.h"#import "DDLog.h"int const ddLogLevel = LOG_LEVEL_VERBOSE;

Logger configuration

#import "DDLog.h"#import "DDASLLogger.h"#import "DDTTYLogger.h"#import "DDFileLogger.h"...- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {     [DDLog addLogger:[DDASLLogger sharedInstance]]; [DDLog addLogger:[DDTTYLogger sharedInstance]]; DDFileLogger *fileLogger = [[DDFileLogger alloc] init];  [DDLog addLogger:fileLogger]; [fileLogger release];...

Import your class

#import "DDLog.h"#import "Constants.h"...- (void)someMethod { DDLogVerbose(@"Log this message");}


No more Prefix Headers, please.

You do not need the now deprecated .pch file, simply include a header file where needed.

Logger.h - CocoaLumberjack 1.9.x

#ifndef Project_Logger_h#define Project_Logger_h#if defined(__OBJC__)#import <CocoaLumberjack/DDLog.h>extern int ddLogLevel;#endif#endif

Logger.m

#import "Logger.h"int ddLogLevel = LOG_LEVEL_VERBOSE;

Changes for CocoaLumberjack 2.x

#import <CocoaLumberjack/CocoaLumberjack.h>int ddLogLevel = DDLogLevelVerbose;

If the syntax changes when 2.0 is out of beta please comment or edit.

Example usage in AppDelegate

#import "AppDelegate.h"#import "Logger.h"#import <CocoaLumberjack/DDFileLogger.h>#import <CocoaLumberjack/DDASLLogger.h>#import <CocoaLumberjack/DDTTYLogger.h>@interface AppDelegate ()@property (strong, nonatomic) DDFileLogger *fileLogger;@end@implementation AppDelegate- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{    [DDLog addLogger:[DDASLLogger sharedInstance]];    [DDLog addLogger:[DDTTYLogger sharedInstance]];    DDFileLogger *fileLogger = [[DDFileLogger alloc] init];    fileLogger.rollingFrequency = 60 * 60 * 24; // 24 hour rolling    fileLogger.logFileManager.maximumNumberOfLogFiles = 7;    [DDLog addLogger:fileLogger];    self.fileLogger = fileLogger;    DDLogDebug(@"%s", __PRETTY_FUNCTION__);    return YES;}- (void)applicationWillResignActive:(UIApplication *)application{    DDLogDebug(@"%s", __PRETTY_FUNCTION__);}- (void)applicationDidEnterBackground:(UIApplication *)application{    DDLogDebug(@"%s", __PRETTY_FUNCTION__);}- (void)applicationWillEnterForeground:(UIApplication *)application{    DDLogDebug(@"%s", __PRETTY_FUNCTION__);}- (void)applicationDidBecomeActive:(UIApplication *)application{    DDLogDebug(@"%s", __PRETTY_FUNCTION__);}- (void)applicationWillTerminate:(UIApplication *)application{    DDLogDebug(@"%s", __PRETTY_FUNCTION__);}