首页 > 代码库 > 第四十二篇、自定义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打印
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。