zoukankan      html  css  js  c++  java
  • 自定义的打印语句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 
    %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
    
  • 相关阅读:
    10.23 JSTL
    10.22 EL执行表达式
    10.21 EL表达式(只能在jsp中使用)
    10.20 网站访问量统计(application)
    10.19 JSP内置对象作用域
    10.16 Session和Cookie的区别
    10.15 转发与重定向
    剑指Offer_26_二叉搜索树与双向链表
    剑指Offer_25_复杂链表的复制
    剑指Offer_24_二叉树中和为某一值的路径.md
  • 原文地址:https://www.cnblogs.com/Rong-Shengcom/p/7851060.html
Copyright © 2011-2022 走看看