- 安裝XcodeColors外掛(可使用Alcatraz包管理器安裝)
- 在專案pch檔案新增以下巨集
#import <CocoaLumberjack/CocoaLumberjack.h>
// DDLog部分
#ifdef DEBUG
static const int ddLogLevel = DDLogLevelVerbose;
#else
static const int ddLogLevel = DDLogLevelOff;
#endif
複製程式碼
-
修改專案scheme -> Run -> Environment Variables 新增XcodeColors:YES
-
開始使用
//新增控制檯輸出Logger
[DDLog addLogger:[DDTTYLogger sharedInstance] withLevel:DDLogLevelAll];
//允許著色
[[DDTTYLogger sharedInstance] setColorsEnabled:YES];
//輸出資訊
DDLogError(@"錯誤資訊"); //紅色
DDLogWarn(@"警告"); //橙色
DDLogInfo(@"提示資訊"); //預設顏色
DDLogDebug(@"除錯資訊"); //預設顏色
DDLogVerbose(@"詳細資訊"); //預設顏色
複製程式碼
