打造多彩的Xcode console系统

一、 下载日志、log分级模块

1.安装CocoaLumberjack

1
pod 'CocoaLumberjack'

  1. 做出相关配置Get started using Lumberjack
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    //PrefixHeader.pch文件中
    #define LOG_LEVEL_DEF ddLogLevel
    #import <CocoaLumberjack/CocoaLumberjack.h>
    #ifdef DEBUG
    static DDLogLevel __unused ddLogLevel = DDLogLevelAll;
    #else
    static DDLogLevel __unused ddLogLevel = DDLogLevelOff;
    #endif

    //AppDelegate.m中 didFinishLaunchingWithOptions
    [DDLog addLogger:[DDOSLogger sharedInstance]]; // Uses os_log

    // 日志写入
    // DDFileLogger *fileLogger = [[DDFileLogger alloc] init]; // File Logger
    // fileLogger.rollingFrequency = 60 * 60 * 24; // 24 hour rolling
    // fileLogger.logFileManager.maximumNumberOfLogFiles = 7;
    // [DDLog addLogger:fileLogger];
    [[DDTTYLogger sharedInstance] setColorsEnabled:YES];

    DDLogVerbose(@"Verbose");
    DDLogDebug(@"Debug");
    DDLogInfo(@"Info");
    DDLogWarn(@"Warn");
    DDLogError(@"Error");

二、下载xcode插件,让xcode支持console栏的多颜色
XcodeColors

但是Xcode8之后苹果禁止了使用自定义插件。所以目前导入之后,console栏无法显示出彩色。

这里找到一个解决方法(没有尝试过)先记录下:
https://blog.csdn.net/kcetry/article/details/79339712

首先我们知道,从Xcode8开始,Xcode屏蔽了第三方插件,导致插件无法使用。
解决方法是使用证书对Xcode进行签名(Github上XVim2的指引),再安装XcodeColors
需要注意的是第二步

假如你已经有开发者证书,并且用第二个证书签名,那么第三步的命令就是
sudo codesign -f -s WV87GNFZXS /Applications/Xcode.app
安装XcodeColors时,别忘了执行
./update_compat.sh
最后还要添加环境变量
Product->Scheme->Edit Scheme->Run->Environment Variables