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
是一个内置于Apple提供的Foundation框架中的函数.我从来没有听说过DLog
,所以我认为它是一个非标准函数,由您正在查看的代码实现.
嗨,在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)
归档时间: |
|
查看次数: |
20101 次 |
最近记录: |