iOS NSLog去掉时间戳及其余输出样式

1.通常项目中个人NSLog会在Prefix.pch文件添加以下代码,已保证在非调试状态下NSLog不工做spa






#ifdef DEBUG调试

#define NSLog(...) NSLog(__VA_ARGS__)日志

#elseorm

#define NSLog(...)string

#endifit

2.在项目中若是没作任何处理的话会输出以下信息,前面有一个时间戳table


2014-11-07 08:25:40.885 zcsy[673:8937] cell的高度258.684998ast

咱们修改下宏以下:import






#ifdef DEBUGim

#define NSLog(FORMAT, ...) fprintf(stderr,"%s\n",[[NSString stringWithFormat:FORMAT, ##__VA_ARGS__] UTF8String]);

#else

#define NSLog(...)

#endif

通过上面的修改咱们能够输出 纯净的内容以下:


cell的高度258.684998

咱们能够用更好的版本我推荐用这个打印咱们的日志:






#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

这样咱们的输出就是这样:



//它会输出文件名,和打印的具体行号

DealItemCell.m:307cell的高度258.684998

相关文章
相关标签/搜索