zoukankan      html  css  js  c++  java
  • iOS NSLog去掉时间戳及其他输出样式

    1.一般项目中我的NSLog会在Prefix.pch文件添加如下代码,已保证在非调试状态下NSLog不工作
     
    1
    2
    3
    4
    5
    #ifdef DEBUG
    #define NSLog(...) NSLog(__VA_ARGS__)
    #else
    #define NSLog(...)
    #endif

    2.在项目中如果没做任何处理的话会输出如下信息,前面有一个时间戳

     
    1
    2014-11-07 08:25:40.885 zcsy[673:8937] cell的高度258.684998

    我们修改下宏如下:

     
    1
    2
    3
    4
    5
    #ifdef DEBUG
    #define NSLog(FORMAT, ...) fprintf(stderr,"%s ",[[NSString stringWithFormat:FORMAT, ##__VA_ARGS__] UTF8String]);
    #else
    #define NSLog(...)
    #endif

    经过上面的修改我们可以输出 纯净的内容如下:

     
    1
    cell的高度258.684998

    我们可以用更好的版本我推荐用这个打印我们的日志:

     
    1
    2
    3
    4
    5
    #ifdef DEBUG
    #define NSLog(FORMAT, ...) fprintf(stderr,"%s:%d %s ",[[[NSString stringWithUTF8String:__FILE__] lastPathComponent] UTF8String], __LINE__, [[NSString stringWithFormat:FORMAT, ##__VA_ARGS__] UTF8String]);
    #else
    #define NSLog(...)
    #endif

    这样我们的输出就是这样:

     
    1
    2
    //它会输出文件名,和打印的具体行号
    DealItemCell.m:307 cell的高度258.684998
     

    http://www.guoms.com/?p=124

  • 相关阅读:
    回溯算法
    回溯算法
    回溯算法
    回溯算法思想
    贪心算法
    C#多线程操作界面控件的解决方案
    jQuery教程
    html css JavaScript网页渲染
    jQuery与JavaScript与ajax三者的区别与联系
    asp.net MVC中form提交和控制器接受form提交过来的数据
  • 原文地址:https://www.cnblogs.com/geek6/p/4353239.html
Copyright © 2011-2022 走看看