Log levels: off, error, warn, info, debug, verbose
一、用到的:
#import <CocoaLumberjack/CocoaLumberjack.h>
#import <CocoaLumberjack/DDTTYLogger.h>
// Per-file log level for CocoaLumbejack (logging framework)
#if DEBUG
static const int ddLogLevel = DDLogLevelVerbose;
#else
static const int ddLogLevel = DDLogLevelWarn;
#endif
#pragma unused(ddLogLevel)
[DDLog addLogger:[DDTTYLogger sharedInstance]];//写终端
[DDLog addLogger:[DDFileLogger new]]; //写文件
//这里是0.
NSLog(@"%d",DD_LEGACY_MACROS);
DDLogVerbose(@"Creating database instance...");
DDLogError(@"Unable to register extension: order");
CocoaLumberjack.h
DDLogMacros.h
或者
#define DD_LEGACY_MACROS 0
DDLog.h
新版本。
二、用不到的
1.9.x的老版本。
DDLog.h
#if DD_LEGACY_MACROS ///
#warning CocoaLumberjack 1.9.x legacy macros enabled. \
Disable legacy macros by importing CocoaLumberjack.h or DDLogMacros.h instead of DDLog.h or add `#define DD_LEGACY_MACROS 0` before importing DDLog.h.
DDLog.h
#ifndef DD_LEGACY_MACROS
#define DD_LEGACY_MACROS 1
#endif
// DD_LEGACY_MACROS is checked in the file itself
#import "DDLegacyMacros.h"
#ifndef x //先测试x是否被宏定义过
#define x
程序段1 //如果x没有被宏定义过,定义x,并编译程序段 1
#else
程序段2 //如果x已经定义过了则编译程序段2的语句,“忽视”程序段 1。
#endif//终止if
#if(条件满足)
执行代码1
#else
执行代码2
#endif
#if 0
...............
#endif
当中的语句, 不会被编译(在预编译是被删掉了)。
说白了, 就是没有用的语句
1,
DDLogVerbose(@"Creating view...");
do { if(ddLogLevel & DDLogFlagVerbose) [DDLog log : __objc_yes level : ddLogLevel flag : DDLogFlagVerbose context : 0 file : "/Users/huchu/Documents/apple/iOS/UI/UITableViewEdit/UITableViewEdit/AppDelegate.m" function : __PRETTY_FUNCTION__ line : 84 tag : ((void *)0) format : (@"Creating database instance...")]; } while(0);
2, DDLogError(@"Unable to register extension: order");
do { if(ddLogLevel & DDLogFlagError) [DDLog log : __objc_no level : ddLogLevel flag : DDLogFlagError context : 0 file : "/Users/huchu/Documents/apple/iOS/UI/UITableViewEdit/UITableViewEdit/AppDelegate.m" function : __PRETTY_FUNCTION__ line : 99 tag : ((void *)0) format : (@"Unable to register extension: order")]; } while(0);
#define LOG_MAYBE(async, lvl, flg, ctx, fnct, frmt, ...) \
do { if(lvl & flg) LOG_MACRO(async, lvl, flg, ctx, nil, fnct, frmt, ##__VA_ARGS__); } while(0)
#define LOG_MAYBE(async, lvl, flg, ctx, tag, fnct, frmt, ...) \
do { if(lvl & flg) LOG_MACRO(async, lvl, flg, ctx, tag, fnct, frmt, ##__VA_ARGS__); } while(0)
#define LOG_MACRO(isAsynchronous, lvl, flg, ctx, atag, fnct, frmt, ...) \
[DDLog log : isAsynchronous \
level : lvl \
flag : flg \
context : ctx \
file : __FILE__ \
function : fnct \
line : __LINE__ \
tag : atag \
format : (frmt), ## __VA_ARGS__]
#define LOG_MACRO(isAsynchronous, lvl, flg, ctx, atag, fnct, frmt, ...) \
[DDLog log : isAsynchronous \
level : lvl \
flag : flg \
context : ctx \
file : __FILE__ \
function : fnct \
line : __LINE__ \
tag : atag \
format : (frmt), ## __VA_ARGS__]
日志颜色
安装插件 https://github.com/robbiehanson/XcodeColors
./update_compat.sh
xcode插件无效解决方法: https://github.com/inket/update_xcode_plugins
gem install update_xcode_plugins
update_xcode_plugins
update_xcode_plugins --unsign
update_xcode_plugins --install-launch-agent
添加环境变量 XcodeColors:YES
管理插件的插件https://github.com/alcatraz/Alcatraz/issues/475
Select Package Manager from the Window menu, then check or uncheck packages to install or remove them. You'll need to restart Xcode after installing plugins or templates. Installed plugins are checked and updated each time Alcatraz is launched.
rm -rf ~/Library/Application\ Support/Developer/Shared/Xcode/Plug-ins/Alcatraz.xcplugin
To remove all packages installed via Alcatraz, run rm -rf ~/Library/Application\ Support/Alcatraz/