1 /* #define DEBUG */ 2 /* #define VERBOSE */ 3 4 /* 5 * Enable verbose logging if requested on platforms that support it. 6 * 7 * Verbose logging adds metadata to printf, including the source file location 8 * from where printf was called and the time it was called at runtime. 9 */ 10 #if defined(DEBUG) && defined(VERBOSE) && defined(__GNUC__) 11 #include <stdio.h> 12 #include <time.h> 13 14 #define printf(args...) do { \ 15 time_t now = time(NULL); \ 16 printf("\n### %s, line %d in %s() @ %s", __FILE__, __LINE__, __FUNCTION__, ctime(&now)); \ 17 printf(args); \ 18 } while(0) 19 #endif 20 21 22 /* 23 * Define a convenience macro DEBUG_PRINTF(). This macro resolves to printf() 24 * if and only if DEBUG is enabled, otherwise resolves to nothing. In other 25 * words, 26 * 27 * DEBUG_PRINTF("Hello, world!\n"); 28 * 29 * ... is equivalent to: 30 * 31 * #if defined(DEBUG) 32 * printf("Hello, world!\n"); 33 * #endif 34 * 35 * (To be precise, the semicolon falls outside of the #if test, but an empty 36 * semicolon resolves to nothing in standard C.) 37 * 38 * If VERBOSE logging is enabled, DEBUG_PRINTF should resolve to the verbose 39 * version of printf() defined earlier in this file. 40 */ 41 #if defined(DEBUG) 42 #define DEBUG_PRINTF(...) printf(__VA_ARGS__) 43 #else 44 #define DEBUG_PRINTF(...) 45 #endif 46