Global log level for CocoaLumberjack

后端 未结 12 1019
[愿得一人]
[愿得一人] 2020-12-23 20:19

I\'m using CocoaLumberjack in an iPhone project, to log some information.

I\'ve followed the Getting started guide, and everything works fine, but there is one thing

12条回答
  •  被撕碎了的回忆
    2020-12-23 21:09

    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 
    extern int ddLogLevel;
    
    #endif
    
    #endif
    

    Logger.m

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

    Changes for CocoaLumberjack 2.x

    #import 
    
    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 
    #import 
    #import 
    
    
    
    @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__);
    }
    

提交回复
热议问题