使用CocoaLumberjack的一些问题记录

想在Xcode中整一个彩色日志显示,按照GettingStarted.md 一文中的步骤将CocoaLumberjack 2.x整合进个人项目中来,遇到一些问题,固然不乏一些坑,做个记录。ios


整合步骤:git

  • Drag CocoaLumberjack/Framework/{Desktop/Mobile}/Lumberjack.xcodeproj into your projectgithub

  • In your App target Build Settingsxcode

    • Add to 'User Header Search Paths' $(BUILD_ROOT)/../IntermediateBuildFilesPath/UninstalledProducts/include架构

    • Set 'Always Search User Paths' to YESapp

  • In your App target Build Phases框架

    • Add CocoaLumberjack static library target to 'Target Dependencies'ide

    • Add libCocoaLumberjack.a to 'Link Binary With Libraries'post

  • Include the framework in your source files with测试

#import <CocoaLumberjack/CocoaLumberjack.h>


一、首先是编译提示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)");


二、彩色日志显示须要插件XcodeColors插件支持,这个插件我下载的是https://github.com/rvi/XcodeColors里面的,由于它支持了Xcode6.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”


四、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"


五、内存暴涨问题

加入CocoaLumberjack后,模拟器测试正常,真机测试内存暴涨,致使xcode自动终结联机调试,不调用DDLog相关的代码就没有问题。最终缩小范围,发现把上面的第4步中的Environment Variable给删掉就没有问题,我真是晕了。

而另外一个位置的同名项目,我测试是没有这个问题,真是奇哉怪也。

实在是没有办法,把DerivedData里的全部app文件夹所有删掉,再从新运行,就没有问题了。猜想是由于同名项目的缘故?


六、使用静态库

原本解决了上面的问题后使用CocoaLumberjack基本就没什么问题了,但是不幸又被我发现了一个问题,那就是当我要修改app图标和启动图片的时候,即在General--App Icons and Launch Images中点向右箭头时,进入的倒是项目Lumberjack.xcodeproj的启动图片设置界面。这说明嵌入Lumberjack.xcodeproj后App Icons and Launch Images混乱了。

因而我想到了使用静态库,在网上找到一个现成的CocoaLumberjack静态库工程,连接是https://github.com/NachoMan/CocoaLumberjack-Static。下载后先执行git submodule update --init --recursive命令更新CocoaLumberjack库,再执行build.sh脚本便可生成一个zip包,里面包含了.a文件和头文件,复制到本身的工程中添加就好了。

能够用lipo -info xxxxx.a命令来检查生成的.a文件的CPU架构。

参考:
iOS开源项目之日志框架CocoaLumberjack
利用 CocoaLumberjack 搭建本身的 Log 系统

Colorful XCode Console

相关文章
相关标签/搜索