Skip to content

Instantly share code, notes, and snippets.

@zekunyan
Created March 15, 2015 09:52
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save zekunyan/2f2356136b9b40348584 to your computer and use it in GitHub Desktop.
Save zekunyan/2f2356136b9b40348584 to your computer and use it in GitHub Desktop.
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