自定义的打印语句NSLog在控制台输出不完整的完美解决

之前定义日志输出时用的下面的方法

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 \n%s\n", 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\n%s\n",[str UTF8String],[[[NSString stringWithUTF8String:__FILE__] lastPathComponent] UTF8String], __LINE__,__PRETTY_FUNCTION__,[[NSString stringWithFormat:FORMAT, ##__VA_ARGS__] UTF8String]);\
}

#else
 # define LYLog(...);
#endif

 

转载于:https://www.cnblogs.com/Rong-Shengcom/p/7851060.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值