欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

CocoaLumberjack 的使用

最编程 2024-02-25 10:25:11
...
  1. 安装XcodeColors插件 下载地址:https://github.com/robbiehanson/XcodeColors 安装方法: 下载并解压缩XcodeColors-master.zip 打开XcodeColors项目,编译项目可以自动将插件安装至~/Library/Application Support/Developer/Shared/Xcode/Plug-ins/XcodeColors.xcplugin 重新启动Xcode 再次打开XcodeColors项目 运行TestXcodeColors测试插件是否安装成功

  2. 下载CocoaLumberjack开源框架 下载地址:https://github.com/CocoaLumberjack/CocoaLumberjack

  3. 新建项目,将CocoaLumberjack拖入项目中

  4. 创建Common.h #ifdef DEBUG static const int ddLogLevel = LOG_LEVEL_VERBOSE; #else static const int ddLogLevel = LOG_LEVEL_OFF; #endif

  5. 在xxx-Prefix.pch中添加Common.h的引入 #import "Common.h"

  6. 实例化DDLog 在- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

方法中设置DDLog

// 实例化 lumberjack [DDLog addLogger:[DDTTYLogger sharedInstance]]; // 允许颜色 [[DDTTYLogger sharedInstance] setColorsEnabled:YES]; 使用方法 lumberjack提供了四种Log方法

DDLogError(@"错误信息"); // 红色 DDLogWarn(@"警告"); // 橙色 DDLogInfo(@"提示信息"); // 默认是黑色 DDLogVerbose(@"详细信息"); // 默认是黑色

其他 如果要修改Log输出的颜色可以使用如下代码:

[[DDTTYLogger sharedInstance] setForegroundColor:[UIColor blueColor] backgroundColor:nil forFlag:LOG_FLAG_INFO];

此文转载自:趣味苹果开发 欢迎访问本人技术微博 趣味苹果开发 相互交流,共同进步! 欢迎访问本人新浪微博 可可爸刘凡http://weibo.com/liufan2012