Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Objective-C NSLog enhance
#define NEED_DEBUG
#ifdef NEED_DEBUG
#define NSLog(format, ...) \
do { \
NSLog(@"<%@ : %d : %s>-%@", \
[[NSString stringWithUTF8String:__FILE__] lastPathComponent], \
__LINE__, \
__FUNCTION__, \
[NSString stringWithFormat:format, ##__VA_ARGS__]); \
} while(0)
#else
#define NSLog(format, ...) do{ } while(0)
#endif
#define LOG_LEVEL_DEBUG
#define LOG_LEVEL_INFO
#define LOG_LEVEL_ERROR
#ifdef LOG_LEVEL_DEBUG
#define DLog(format, ...) NSLog(@"<DEBUG>: %@", [NSString stringWithFormat:format, ##__VA_ARGS__])
#else
#define DLog(format, ...) do{ } while(0)
#endif
#ifdef LOG_LEVEL_INFO
#define ILog(format, ...) NSLog(@"<Info>: %@", [NSString stringWithFormat:format, ##__VA_ARGS__])
#else
#define ILog(format, ...) do{ } while(0)
#endif
#ifdef LOG_LEVEL_ERROR
#define ELog(format, ...) NSLog(@"<Error>: %@", [NSString stringWithFormat:format, ##__VA_ARGS__])
#else
#define ELog(format, ...) do{ } while(0)
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.