- 一般项目中我的NSLog会在Prefix.pch文件添加如下代码,已保证在非调试状态下NSLog不工作
#ifdef DEBUG
#define NSLog(...) NSLog(__VA_ARGS__)
#else
#define NSLog(...)
#endif```
2. 在项目中如果没做任何处理的话会输出如下信息,前面有一个时间戳
**2016-09-01 10:42:16.787 test_tabBarController[19226:1694499] <UIView: 0x7fc430d3db20; frame = (0 0; 414 736); autoresize = W+H; layer = <CALayer: 0x7fc430d12ba0>>**

我们修改下宏如下:
ifdef DEBUG
define NSLog(FORMAT, ...) fprintf(stderr,"%s\n",[[NSString stringWithFormat:FORMAT, ##VA_ARGS] UTF8String]);
else
define NSLog(...)
endif```
经过上面的修改我们可以输出 纯净的内容如下:

3.我们可以用更好的版本我推荐用这个打印我们的日志:
#ifdef DEBUG
#define NSLog(FORMAT, ...) fprintf(stderr,"%s:%d\t%s\n",[[[NSString stringWithUTF8String:__FILE__] lastPathComponent] UTF8String], __LINE__, [[NSString stringWithFormat:FORMAT, ##__VA_ARGS__] UTF8String]);
#else
#define NSLog(...)
#endif```
这样我们的输出就是这样:
他可以打印出行号 和 对应的class类名 很强大有木有

> 如果本文帮到了你,敬请给出喜欢❤️ 感谢你的小手✋ 关注作者😍 后续更新iOS刀法
[传送门](http://www.jianshu.com/users/29e2c915351f/latest_articles)
网友评论