1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
| #ifndef PRINT_H #define PRINT_H
#include <stdio.h> #include <windows.h>
DWORD enableColorful(void);
#define PRINT_LEVEL LEVEL_DEBUG #define PRINT_COLORFUL 1
#define LEVEL_NANO 0 #define LEVEL_ERROR 1 #define LEVEL_WARN 2 #define LEVEL_INFO 3 #define LEVEL_ENTRY 4 #define LEVEL_DEBUG 5
#define COLOR_GRAY "\033[37m" #define COLOR_GREEN "\033[32m" #define COLOR_YELLOW "\033[33m" #define COLOR_DARKGRAY "\033[30m" #define COLOR_BLACK "\033[30m" #define COLOR_NOCOLOR "\033[0m" #define COLOR_DEEPBLUE "\033[34m" #define COLOR_RED "\033[31m"
#define PR_CUST(level, ...) \ do \ { \ if (level <= PRINT_LEVEL) \ printf(__VA_ARGS__); \ } while (0);
#if PRINT_COLORFUL #define pr_nano(fmt, ...) PR_CUST(LEVEL_NANO, fmt, ##__VA_ARGS__) #define pr_err(fmt, ...) PR_CUST(LEVEL_ERROR, COLOR_RED "ERROR:" fmt COLOR_NOCOLOR, ##__VA_ARGS__) #define pr_warn(fmt, ...) PR_CUST(LEVEL_WARN, COLOR_YELLOW "WARN: " fmt COLOR_NOCOLOR, ##__VA_ARGS__) #define pr_info(fmt, ...) PR_CUST(LEVEL_INFO, COLOR_GREEN "INFO: " fmt COLOR_NOCOLOR, ##__VA_ARGS__) #define pr_bug(fmt, ...) PR_CUST(LEVEL_DEBUG, COLOR_DEEPBLUE "DEBUG: " fmt COLOR_NOCOLOR, ##__VA_ARGS__) #define pr_entry(inout) PR_CUST(LEVEL_ENTRY, "%s() %s", __func__, #inout) #else #define pr_nano(fmt, ...) PR_CUST(LEVEL_NANO, fmt, ##__VA_ARGS__) #define pr_err(fmt, ...) PR_CUST(LEVEL_ERROR, "ERROR:" fmt, ##__VA_ARGS__) #define pr_warn(fmt, ...) PR_CUST(LEVEL_WARN, "WARN: " fmt, ##__VA_ARGS__) #define pr_info(fmt, ...) PR_CUST(LEVEL_INFO, "INFO: " fmt, ##__VA_ARGS__) #define pr_bug(fmt, ...) PR_CUST(LEVEL_DEBUG, "DEBUG: " fmt, ##__VA_ARGS__) #define pr_entry(inout) PR_CUST(LEVEL_ENTRY, "%s() %s", __func__, #inout) #endif
#endif
|