1. 安裝XcodeColors插件
2、下載CocoaLumberjack開(kāi)源框架
3、使用
#ifdef DEBUG
static const int ddLogLevel = LOG_LEVEL_VERBOSE;
#else
static const int ddLogLevel = LOG_LEVEL_OFF;
#endif
setenv("XcodeColors", "YES", 0);
// 實(shí)例化 lumberjack
[DDLog addLogger:[DDTTYLogger sharedInstance]];
// 允許顏色
[[DDTTYLogger sharedInstance] setColorsEnabled:YES];
lumberjack提供了四種Log方法
DDLogError(@"錯(cuò)誤信息"); // 紅色
DDLogWarn(@"警告"); // 橙色
DDLogInfo(@"提示信息"); // 默認(rèn)是黑色
DDLogVerbose(@"詳細(xì)信息"); // 默認(rèn)是黑色
其他
如果要修改Log輸出的顏色可以使用如下代碼:
[[DDTTYLogger sharedInstance] setForegroundColor:[UIColor blueColor] backgroundColor:nil forFlag:LOG_FLAG_INFO];
插件目錄看:
sudo open /Users/你的用戶名/Library/Application\ Support/Developer/Shared/Xcode/Plug-ins
打開(kāi)終端,輸入以下代碼:
defaults read /Applications/Xcode.app/Contents/Info DVTPlugInCompatibilityUUID
獲取到DVTPlugInCompatibilityUUID爽航,然后
$ find ~/Library/Application\ Support/Developer/Shared/Xcode/Plug-ins -name Info.plist -maxdepth 3 | xargs -I{} defaults write {} DVTPlugInCompatibilityUUIDs -array-add UUID碼
參考使用