首页 > 代码库 > 第四十二篇、自定义Log打印

第四十二篇、自定义Log打印

在开发的过程中,打印调试日志是一项比不可少的工程,但是在iOS 10中NSLog打印日志被屏蔽了,就不得不使用自定义Log

#ifdef DEBUG#define LRString [NSString stringWithFormat:@"%s",__FILE__].lastPathComponent#define LRLog(...) NSLog(@"%@ 第%d行 \n%@\n\n",LRString,__LINE__,[NSString stringWithFormat:__VA_ARGS__])#else#define LRLog(...)#endif

 

#ifdef DEBUG#define LRString [NSString stringWithFormat:@"%s", __FILE__].lastPathComponent#define LRLog(...)  printf("%s 第%d行: %s\n\n", [LRString UTF8String] ,__LINE__, [[NSString stringWithFormat:__VA_ARGS__] UTF8String]);#else#define LRLog(...)#endif

使用UTF8String的原因就是printf是C语言的,所以需要通过这个方法转换一下才能打印。

第四十二篇、自定义Log打印