天天看點

[紹棠] iOS-CocoaLumberjack(DDLog)日志架構使用

  1. 安裝XcodeColors插件(可使用Alcatraz包管理器安裝)
  2. 在項目pch檔案添加以下宏
    #import <CocoaLumberjack/CocoaLumberjack.h>
    // DDLog部分
    #ifdef DEBUG
    static const int ddLogLevel = DDLogLevelVerbose;
    #else
    static const int ddLogLevel = DDLogLevelOff;
    #endif                
  3. 修改項目scheme -> Run -> Environment Variables 添加XcodeColors:YES
  4. 開始使用
//添加控制台輸出Logger
[DDLog addLogger:[DDTTYLogger sharedInstance] withLevel:DDLogLevelAll];
//允許着色
[[DDTTYLogger sharedInstance] setColorsEnabled:YES];
    
//輸出資訊
DDLogError(@"錯誤資訊");    //紅色
DDLogWarn(@"警告");        //橙色
DDLogInfo(@"提示資訊");     //預設顔色
DDLogDebug(@"調試資訊");    //預設顔色
DDLogVerbose(@"詳細資訊");  //預設顔色