第四十二篇自定义Log打印

Posted 久冬不雨

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了第四十二篇自定义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打印的主要内容,如果未能解决你的问题,请参考以下文章