zoukankan      html  css  js  c++  java
  • 利用CocoaLumberjack框架+XcodeColors插件,调试输出有彩色的信息

    效果如下:

    步骤:

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

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

    3. 添加代码

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

    内容如:

    #ifndef <你的项目名>_PrefixHeader_pch
    #define <你的项目名>_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) 在需要调用输出的地方用这样的代码:(图中的例子是写在Button的点击功能里)

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

    推荐阅读:

    iOS开源项目之日志框架CocoaLumberjack

  • 相关阅读:
    《构建之法》阅读笔记二
    《构建之法》阅读笔记一
    软件工程个人课程总结
    纯随机数生成器
    递归方法
    素数的输出
    字母统计|英语的26 个字母在一本小说中是如何分布的
    类的声明
    FileInputStream类与FileOutputStream类
    验证码|程序登录界面
  • 原文地址:https://www.cnblogs.com/Bob-wei/p/4718792.html
Copyright © 2011-2022 走看看