自定义打印日志

来源:互联网 发布:2016好声音网络直播 编辑:程序博客网 时间:2024/05/19 03:17

NSStringFromCGRect 打印 view的frame

如:

NSLog(@"view1 frame:%@========view1 bounds:%@",NSStringFromCGRect(view1.frame),NSStringFromCGRect(view1.bounds)); 

#define _SHOW_DEBUG_LOG_

#ifdef  _SHOW_DEBUG_LOG_

#define DebugLog(...) NSLog(__VA_ARGS__)

#else

#define DebugLog(...)

#endif







转载的文章解释:




#define TTLOGLEVEL_INFO     5

#define TTLOGLEVEL_WARNING  3

#define TTLOGLEVEL_ERROR    1

 

#ifndef TTMAXLOGLEVEL

  #define TTMAXLOGLEVEL TTLOGLEVEL_WARNING

#endif

 

// The general purpose logger. This ignores logging levels.

#ifdef DEBUG

//作者:禚来强 邮箱:zhuolaiqiang@gmail.com

  #define TTDPRINT(xx, ...)  NSLog(@"%s(%d): " xx, __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__)

#else

  #define TTDPRINT(xx, ...)  ((void)0)

#endif // #ifdef DEBUG

 

// Prints the current method's name.

#define TTDPRINTMETHODNAME() TTDPRINT(@"%s", __PRETTY_FUNCTION__)

 

// Debug-only assertions.

#ifdef DEBUG

//作者:禚来强 邮箱:zhuolaiqiang@gmail.com

 

#import <TargetConditionals.h>

 

#if TARGET_IPHONE_SIMULATOR

 

  int TTIsInDebugger();

  // We leave the __asm__ in this macro so that when a break occurs, we don't have to step out of

  // a "breakInDebugger" function.

  #define TTDASSERT(xx) { if (!(xx)) { TTDPRINT(@"TTDASSERT failed: %s", #xx); /

                                      if (TTIsInDebugger()) { __asm__("int $3/n" : : ); }; } /

                        } ((void)0)

#else

  #define TTDASSERT(xx) { if (!(xx)) { TTDPRINT(@"TTDASSERT failed: %s", #xx); } } ((void)0)

//作者:禚来强 邮箱:zhuolaiqiang@gmail.com

#endif // #if TARGET_IPHONE_SIMULATOR

 

#else

  #define TTDASSERT(xx) ((void)0)

#endif // #ifdef DEBUG

 

// Log-level based logging macros.

#if TTLOGLEVEL_ERROR <= TTMAXLOGLEVEL

  #define TTDERROR(xx, ...)  TTDPRINT(xx, ##__VA_ARGS__)

#else

  #define TTDERROR(xx, ...)  ((void)0)

#endif // #if TTLOGLEVEL_ERROR <= TTMAXLOGLEVEL

 

#if TTLOGLEVEL_WARNING <= TTMAXLOGLEVEL

  #define TTDWARNING(xx, ...)  TTDPRINT(xx, ##__VA_ARGS__)

#else

  #define TTDWARNING(xx, ...)  ((void)0)

#endif // #if TTLOGLEVEL_WARNING <= TTMAXLOGLEVEL

 

#if TTLOGLEVEL_INFO <= TTMAXLOGLEVEL

  #define TTDINFO(xx, ...)  TTDPRINT(xx, ##__VA_ARGS__)

#else

  #define TTDINFO(xx, ...)  ((void)0)

#endif // #if TTLOGLEVEL_INFO <= TTMAXLOGLEVEL

 

#ifdef DEBUG

  #define TTDCONDITIONLOG(condition, xx, ...) { if ((condition)) { /

                                                  TTDPRINT(xx, ##__VA_ARGS__); /

                                                } /

                                              } ((void)0)

#else

  #define TTDCONDITIONLOG(condition, xx, ...) ((void)0)

#endif // #ifdef DEBUG

 

 

一。log是什么?

three20Debug添加新的特性,可以更加容易的停止在控制台中打印log。可以有选择性的打印某些信息。

 

二。如何让three20打印log?

yourproject->getinfo—>bulid->Gcc_preprocessor_definitions->debug中定义一个DEBUG宏。你不应该在你的release(发布版本)版本中定义这个宏,要不然你的app会被拒绝。

千万不要把调试版本提交给appstore。

//作者:禚来强 邮箱:zhuolaiqiang@gmail.com

 

三。如何打印log?

ttdebug引入了一个具有不同优先级的宏。如下:

 

TTDERROR(text, ...)    // Priority level 1

TTDWARNING(text, ...)  // Priority level 3

TTDINFO(text, ...)     // Priority level 5

TTDPRINT(text, ...)    // Always prints

 

三。优先级意味着什么?

如果宏的优先级小于TTMAXLOGEVEL,则就会被打印。所以默认情况下把它设置为3,则优先级别大于3的宏将要不被打印。

//作者:禚来强 邮箱:zhuolaiqiang@gmail.com

 

如果TTMAXLOGEVEL没有被设置,则缺省是3,这意味着只有warning和error会被打印。

 

四。有条件的打印

//作者:禚来强 邮箱:zhuolaiqiang@gmail.com

  #define TTDCONDITIONLOG(condition, xx, ...) { if ((condition)) { /

                                                  TTDPRINT(xx, ##__VA_ARGS__); /

                                                } /

                                              } ((void)0)


原创粉丝点击