I'm looking for a review of my macros. I have these in the project pre-compile header. I tent to copy them into all my new projects as well, unless its a very simple project.
#ifdef __APPLE__
#import <TargetConditionals.h>
#endif
// turn on or off different types of logging. ALog() is always logged.
#define LOG_D // Turn on standard debug messages DLog();
#define LOG_N // Turn on network debug messages NLog();
#define LOG_DB // Turn on database debug messages DBLog();
#undef LOG_V // Turn off verose debug messages VLog();
#undef LOG_UI // Turn off popup messages UILog();
// -- You should not have to mess with anything below this line --
// Be safe, start with all things defined
#define DEBUGLOG(...) do {} while (0)
#define ALERTLOG(...) do {} while (0)
#define ALWAYSLOG(...) do {} while (0)
// Define three basic debug types, DEBUGLOG, ALERTLOG and ALWAYSLOG
// These macros generally should not be called directly
// DEBUGLOG - show a message only when compiled for debugging
// ALERTLOG - show a popup window message only when compile for debugging
// ALWAYSLOG - show a message debugging and release
#ifdef __APPLE__
#ifdef DEBUG
#undef DEBUGLOG
#define DEBUGLOG(type, fmt, ...) NSLog((@"%@: %s [Line %d] " fmt), type, __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__)
#undef ALERTLOG
#if TARGET_OS_MAC
#define ALERTLOG(fmt, ...) DEBUGLOG(@"I", fmt, ##__VA_ARGS__)
#else
#define ALERTLOG(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]; }
#endif
#endif
#undef ALWAYSLOG
#define ALWAYSLOG(type, fmt, ...) NSLog((@"%@: %s [Line %d] " fmt), type, __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__)
#endif
// Create some standard logging macros
#ifdef LOG_D
#define DLog(fmt, ...) DEBUGLOG(@"D", fmt, ##__VA_ARGS__)
#else
#define DLog(...) do {} while (0)
#endif
#ifdef LOG_N
#define NLog(fmt, ...) DEBUGLOG(@"Net", fmt, ##__VA_ARGS__)
#else
#define NLog(...) do {} while (0)
#endif
#ifdef LOG_DB
#define DBLog(fmt, ...) DEBUGLOG(@"DB", fmt, ##__VA_ARGS__)
#else
#define DBLog(...) do {} while (0)
#endif
#ifdef LOG_V
#define VLog(fmt, ...) DEBUGLOG(@"V", fmt, ##__VA_ARGS__)
#else
#define VLog(...) do {} while (0)
#endif
#ifdef LOG_UI
#define UILog(fmt, ...) ALERTLOG(fmt, ##__VA_ARGS__)
#else
#define UILog(...) do {} while (0)
#endif
#define ALog(fmt, ...) ALWAYSLOG(@"V", fmt, ##__VA_ARGS__)