美文网首页
iOS开发 - 完美解决Xcode NSLog打印不全

iOS开发 - 完美解决Xcode NSLog打印不全

作者: 俺不是大佬儿 | 来源:发表于2019-11-19 17:13 被阅读0次

完美解决Xcode NSLog打印不全的问题

/**
*  完美解决Xcode NSLog打印不全的宏 
*/
#ifdef DEBUG
#define NSLog(FORMAT, ...) {\
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];\
[dateFormatter setDateStyle:NSDateFormatterMediumStyle];\
[dateFormatter setTimeStyle:NSDateFormatterShortStyle];\
NSTimeZone* timeZone = [NSTimeZone timeZoneWithName:@"Asia/Beijing"];\
[dateFormatter setTimeZone:timeZone];\
[dateFormatter setDateFormat:@"HH:mm:ss.SSSSSSZ"];\
NSString *str = [dateFormatter stringFromDate:[NSDate date]];\
fprintf(stderr,"--TIME:%s【FILE:%s--LINE:%d】FUNCTION:%s\n%s\n",[str UTF8String],[[[NSString stringWithUTF8String:__FILE__] lastPathComponent] UTF8String], __LINE__,__PRETTY_FUNCTION__,[[NSString stringWithFormat:FORMAT, ##__VA_ARGS__] UTF8String]);\
}
#else
# define NSLog(...);
#endif

打印结果

/**
*时间 - 【文件名 -- 第几行】方法名 -- 输出的内容
*/
--TIME:16:50:43.922000+0800【FILE:RootTabBarController.m--LINE:61】FUNCTION:-[RootTabBarController _createTabBarItems]
itemViewModel.vcClassName------:MineViewController

相关文章

网友评论

      本文标题:iOS开发 - 完美解决Xcode NSLog打印不全

      本文链接:https://www.haomeiwen.com/subject/xnkgictx.html