Paul Cercueil | 0b2ce71 | 2014-02-17 15:04:18 +0100 | [diff] [blame^] | 1 | |
| 2 | #ifndef DEBUG_H |
| 3 | #define DEBUG_H |
| 4 | |
| 5 | #include <stdio.h> |
| 6 | |
| 7 | #define NODEBUG_L 0 |
| 8 | #define ERROR_L 1 |
| 9 | #define WARNING_L 2 |
| 10 | #define INFO_L 3 |
| 11 | #define DEBUG_L 4 |
| 12 | |
| 13 | #ifndef LOG_LEVEL |
| 14 | #define LOG_LEVEL INFO_L |
| 15 | #endif |
| 16 | |
| 17 | // ------------- |
| 18 | |
| 19 | #ifdef WITH_COLOR_DEBUG |
| 20 | #ifndef COLOR_DEBUG |
| 21 | #define COLOR_DEBUG "\e[0;34m" |
| 22 | #endif |
| 23 | #ifndef COLOR_WARNING |
| 24 | #define COLOR_WARNING "\e[01;35m" |
| 25 | #endif |
| 26 | #ifndef COLOR_ERROR |
| 27 | #define COLOR_ERROR "\e[01;31m" |
| 28 | #endif |
| 29 | |
| 30 | #define COLOR_END "\e[0m" |
| 31 | #endif |
| 32 | |
| 33 | #if (LOG_LEVEL >= DEBUG_L) |
| 34 | # ifdef COLOR_DEBUG |
| 35 | # define DEBUG(str, ...) \ |
| 36 | fprintf(stdout, COLOR_DEBUG "DEBUG: " str COLOR_END, ##__VA_ARGS__) |
| 37 | # else |
| 38 | # define DEBUG(...) \ |
| 39 | fprintf(stdout, "DEBUG: " __VA_ARGS__) |
| 40 | # endif |
| 41 | #else |
| 42 | #define DEBUG(...) |
| 43 | #endif |
| 44 | |
| 45 | #if (LOG_LEVEL >= INFO_L) |
| 46 | # ifdef COLOR_INFO |
| 47 | # define INFO(str, ...) \ |
| 48 | fprintf(stdout, COLOR_INFO str COLOR_END, ##__VA_ARGS__) |
| 49 | # else |
| 50 | # define INFO(...) \ |
| 51 | fprintf(stdout, __VA_ARGS__) |
| 52 | # endif |
| 53 | #else |
| 54 | #define INFO(...) |
| 55 | #endif |
| 56 | |
| 57 | #if (LOG_LEVEL >= WARNING_L) |
| 58 | # ifdef COLOR_WARNING |
| 59 | # define WARNING(str, ...) \ |
| 60 | fprintf(stderr, COLOR_WARNING "WARNING: " str COLOR_END, ##__VA_ARGS__) |
| 61 | # else |
| 62 | # define WARNING(...) \ |
| 63 | fprintf(stderr, "WARNING: " __VA_ARGS__) |
| 64 | # endif |
| 65 | #else |
| 66 | #define WARNING(...) |
| 67 | #endif |
| 68 | |
| 69 | #if (LOG_LEVEL >= ERROR_L) |
| 70 | # ifdef COLOR_ERROR |
| 71 | # define ERROR(str, ...) \ |
| 72 | fprintf(stderr, COLOR_ERROR "ERROR: " str COLOR_END, ##__VA_ARGS__) |
| 73 | # else |
| 74 | # define ERROR(...) \ |
| 75 | fprintf(stderr, "ERROR: " __VA_ARGS__) |
| 76 | # endif |
| 77 | #else |
| 78 | #define ERROR(...) |
| 79 | #endif |
| 80 | |
| 81 | #endif |