NSLog和DLog之间的区别

slo*_*kar 22 logging cocoa objective-c nslog

谁能告诉我NSLog和之间有什么区别DLog

当我查看这个项目代码时,我发现了这个DLog:http://code.google.com/p/iphone-socks-proxy/

Pas*_*cal 69

DLog是一种常用的"调试NSLog"替代方案(仅适用于Google)

这是一套完整的Log #define指令(包括ULog,一种基于UIAlertView的Logging功能)

// DLog will output like NSLog only when the DEBUG variable is set

#ifdef DEBUG
#   define DLog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
#else
#   define DLog(...)
#endif

// ALog will always output like NSLog

#define ALog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);

// ULog will show the UIAlertView only when the DEBUG variable is set 

#ifdef DEBUG
#   define ULog(fmt, ...)  { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:[NSString stringWithFormat:@"%s\n [Line %d] ", __PRETTY_FUNCTION__, __LINE__] message:[NSString stringWithFormat:fmt, ##__VA_ARGS__]  delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil]; [alert show]; }
#else
#   define ULog(...)
#endif
Run Code Online (Sandbox Code Playgroud)

只需将它们放在预编译头(.pch)文件中即可.

(来源:http://overbythere.co.uk/blog/2012/01/alternatives-nslog)


Cod*_*aFi 13

DLog是一个宏,用于条件化NSLog()调试和发布版本中的行为.对于发布版本,它将不会打印. NSLog()用于将格式字符串打印到控制台.

以下是其参考定义:

#ifdef DEBUG
#    define DLog(...) NSLog(__VA_ARGS__)
#else
#    define DLog(...) /* */
#endif
#define ALog(...) NSLog(__VA_ARGS__)
Run Code Online (Sandbox Code Playgroud)

  • 这不是真的.`NSLog`并不打算用于将字符串文字打印到控制台 - 为此,如果你愿意,可以使用`printf`(或`fputs`)和朋友."NSLog"的要点是将有用且有效的信息打印到系统日志中. (5认同)

Kur*_*vis 9

NSLog是一个内置于Apple提供的Foundation框架中的函数.我从来没有听说过DLog,所以我认为它是一个非标准函数,由您正在查看的代码实现.

  • `DLog`代表'Debug Log'(我假设),并且通常是一个宏,如果关闭`DEBUG`环境标志,则评估为空 - 主要是在运送应用程序中. (9认同)

sat*_*ish 8

嗨,在NSLOG替换文件格式的宏cmd下面以及下面我提到的undef Macro以及

定义:

#define _LOG_TO_CONSOLE_ //#undef _LOG_TO_CONSOLE_
#ifdef _LOG_TO_CONSOLE_
#define DLog(format, ...) NSLog(format, ##__VA_ARGS__)
#else
#define DLog(format, ...)
#endif
Run Code Online (Sandbox Code Playgroud)