首页 > 其他 > 详细

利用CocoaLumberjack框架+XcodeColors插件,调试输出有彩色的信息

时间:2015-08-10 19:30:38      阅读:241      评论:0      收藏:0      [点我收藏+]

效果如下:

技术分享

 

步骤:

1. 安装Xcode插件:XcodeColors(方法请参考这里)

2. 为项目添加 CocoaLumberjack 框架(方法请参考这里)

3. 添加代码

(1) 为项目添加 pch 文件,比如文件名为 PrefixHeader.pch

内容是:

#ifndef Demo_PrefixHeader_pch
#define Demo_PrefixHeader_pch

#ifdef __OBJC__
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import "DDLog.h"
#endif

#ifdef DEBUG
static const int ddLogLevel = LOG_LEVEL_VERBOSE;
#else
static const int ddLogLevel = LOG_LEVEL_OFF;
#endif

#endif

 

(2) 修改项目 Build Settings 页,更改左上角的 Basic 为 All,在右侧搜索栏里输入 prefix ,快速找到 Apple LLVM 6.x - Language 下面的 Prefix Header

修改值为 项目名/PrefixHeader.pch (这是一个相对路径,必须以项目名开头)

(3) 在 AppDelegate.m 的  - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions  里

加入代码:(需要头 #import "CocoaLumberjack.h" )

    // Enable XcodeColors
    setenv("XcodeColors", "YES", 0);
    
    // Standard lumberjack initialization
    [DDLog addLogger:[DDTTYLogger sharedInstance]];
    
    // And then enable colors
    [[DDTTYLogger sharedInstance] setColorsEnabled:YES];

(4) 在需要调用输出的地方用这样的代码:

    DDLogError(@"DDLogError");  // Red
    DDLogWarn(@"DDLogWarn");   // Orange
    DDLogInfo(@"DDLogInfo");  // Default (black)
    DDLogVerbose(@"DDLogVerbose");  // Default (black)

 

利用CocoaLumberjack框架+XcodeColors插件,调试输出有彩色的信息

原文:http://www.cnblogs.com/Bob-wei/p/4718792.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!