之前定义日志输出时用的下面的方法
1 #ifdef DEBUG // 调试状态, 打开LOG功能 2 #define CXTLog(...) NSLog(__VA_ARGS__) 3 #else // 发布状态, 关闭LOG功能 4 #define CXTLog(...) 5 #endif
感觉很完美,但是最近升级xcode 9以后发现控制台总是输出不完整,打印接口数据总是打印出一部分,很是郁闷,
直到发现了下面的方法:
1 #ifdef DEBUG // 调试状态, 打开LOG功能
2
3 #define CXTLog( s, ... ) printf("class: <%p %s:(%d) > method: %s
%s
", self, [[[NSString stringWithUTF8String:__FILE__] lastPathComponent] UTF8String], __LINE__, __PRETTY_FUNCTION__, [[NSString stringWithFormat:(s), ##__VA_ARGS__] UTF8String] )
4
5 #else// 发布状态, 关闭LOG功能
6 #define CXTLog( s, ... )
7 #endif
用这个方法解决了控制台输出不完整的问题,整个人就好了!
升级版:
#ifdef DEBUG
#define LYLog(FORMAT, ...) {
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateStyle:NSDateFormatterMediumStyle];
[dateFormatter setTimeStyle:NSDateFormatterShortStyle];
NSTimeZone* timeZone = [NSTimeZone timeZoneWithName:@"Asia/Beijing"];
[dateFormatter setTimeZone:timeZone];
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss.SSSSSSZ"];
NSString *str = [dateFormatter stringFromDate:[NSDate date]];
fprintf(stderr,"TIME:%s【FILE:%s--LINE:%d】FUNCTION:%s
%s
",[str UTF8String],[[[NSString stringWithUTF8String:__FILE__] lastPathComponent] UTF8String], __LINE__,__PRETTY_FUNCTION__,[[NSString stringWithFormat:FORMAT, ##__VA_ARGS__] UTF8String]);
}
#else
# define LYLog(...);
#endif