标签:
想在Xcode中整一个彩色日志显示,按照GettingStarted.md 一文中的步骤将CocoaLumberjack 2.x整合进我的项目中来,遇到一些问题,当然不乏一些坑,作个记录。
整合步骤:
Drag CocoaLumberjack/Framework/{Desktop/Mobile}/Lumberjack.xcodeproj
into your project
In your App target Build Settings
Add to ‘User Header Search Paths‘ $(BUILD_ROOT)/../IntermediateBuildFilesPath/UninstalledProducts/include
Set ‘Always Search User Paths‘ to YES
In your App target Build Phases
Add CocoaLumberjack static library target to ‘Target Dependencies‘
Add libCocoaLumberjack.a
to ‘Link Binary With Libraries‘
Include the framework in your source files with
#import <CocoaLumberjack/CocoaLumberjack.h>
1、首先是编译提示Use of undeclared identifier ‘LOG_LEVEL_VERBOSE‘问题
这个我是按照文档XcodeTricks.md 在pch文件中加了下面的代码:
#ifdef DEBUG static const int ddLogLevel = LOG_LEVEL_VERBOSE; #else static const int ddLogLevel = LOG_LEVEL_WARN; #endif
踩坑1,把LOG_LEVEL_VERBOSE和LOG_LEVEL_WARN换成DDLogLevelVerbose和DDLogLevelError就好了。
修改后的代码应该是:
#ifdef DEBUG static const int ddLogLevel = DDLogLevelVerbose; #else static const int ddLogLevel = DDLogLevelError; #endif
然后在方法application:didFinishLaunchingWithOptions:中添加以下代码设置颜色显示:
[DDLog addLogger:[DDASLLogger sharedInstance]]; [DDLog addLogger:[DDTTYLogger sharedInstance]]; [[DDTTYLogger sharedInstance] setColorsEnabled:YES];
测试颜色显示的代码:
DDLogError(@"Paper jam"); DDLogWarn(@"Toner is low"); DDLogInfo(@"Warming up printer (pre-customization)"); DDLogVerbose(@"Intializing protcol x26 (pre-customization)");
2、彩色日志显示需要插件XcodeColors插件支持,这个插件我下载的是https://github.com/rvi/XcodeColors里面的,因为它支持了Xcode6.3。
3、用CocoaLumberjack Demo里自带的TextXcodeColors工程测试,pod install后打开TextXcodeColors.xcodeproj,编译提示ld: library not found for -lPods-TXC_ios-CocoaLumberjack
又是一个坑。一般来说,pod install后应该生成xcworkspace文件,但是没有生成TextXcodeColors.xcworkspace文件,我就奇怪了。后来才发现,应该是打开Demos.xcworkspace,然后在里面选择TextXcodeColors这个target,当然前提是先要进入TextXcodeColors文件夹执行pod install才行。尽量使用“pod install --verbose --no-repo-update”
4、Demo里测试日志颜色正常,在自己的项目里就不会显示颜色
坑3。奥秘在于要对Project的Scheme作了如下调整:
In Xcode bring up the Scheme Editor (Product -> Edit Scheme...)
Select "Run" (on the left), and then the "Arguments" tab
Add a new Environment Variable named "XcodeColors", with a value of "YES"
参考:
iOS开源项目之日志框架CocoaLumberjack
利用 CocoaLumberjack 搭建自己的 Log 系统
标签:
原文地址:http://my.oschina.net/ioslighter/blog/381201