|
15 | 15 |
|
16 | 16 | #include <stdio.h> |
17 | 17 |
|
| 18 | +#include "common.h" |
| 19 | + |
18 | 20 | /* DEBUG off by default, enable it on a per-file basis. */ |
19 | 21 | #ifndef DEBUG |
20 | 22 | #define DEBUG 0 |
|
31 | 33 | * |
32 | 34 | * \{ */ |
33 | 35 |
|
| 36 | +extern void log_(u8 level, const char *msg, ...) __attribute__ ((weak)); |
| 37 | + |
| 38 | +#define LOG_EMERG 0 /* system is unusable */ |
| 39 | +#define LOG_ALERT 1 /* action must be taken immediately */ |
| 40 | +#define LOG_CRIT 2 /* critical conditions */ |
| 41 | +#define LOG_ERROR 3 /* error conditions */ |
| 42 | +#define LOG_WARN 4 /* warning conditions */ |
| 43 | +#define LOG_NOTICE 5 /* normal but significant condition */ |
| 44 | +#define LOG_INFO 6 /* informational */ |
| 45 | +#define LOG_DEBUG 7 /* debug-level messages */ |
| 46 | + |
| 47 | +/** Log an emergency. |
| 48 | + * \param args `printf` style format and arguments. |
| 49 | + */ |
| 50 | +#define log_emerg(args...) log_(LOG_EMERG, args) |
| 51 | + |
| 52 | +/** Log an alert. |
| 53 | + * \param args `printf` style format and arguments. |
| 54 | + */ |
| 55 | +#define log_alert(args...) log_(LOG_ALERT, args) |
| 56 | + |
| 57 | +/** Log a critical event. |
| 58 | + * \param args `printf` style format and arguments. |
| 59 | + */ |
| 60 | +#define log_crit(args...) log_(LOG_CRIT, args) |
| 61 | + |
34 | 62 | /** Log an error. |
35 | 63 | * \param args `printf` style format and arguments. |
36 | 64 | */ |
37 | | -#define log_error(args...) printf("ERROR: " args) |
| 65 | +#define log_error(args...) log_(LOG_ERROR, args) |
38 | 66 |
|
39 | 67 | /** Log a warning. |
40 | 68 | * \param args `printf` style format and arguments. |
41 | 69 | */ |
42 | | -#define log_warn(args...) printf("WARNING: " args) |
| 70 | +#define log_warn(args...) log_(LOG_WARN, args) |
| 71 | + |
| 72 | +/** Log a notice. |
| 73 | + * \param args `printf` style format and arguments. |
| 74 | + */ |
| 75 | +#define log_notice(args...) log_(LOG_NOTICE, args) |
43 | 76 |
|
44 | 77 | /** Log an information message. |
45 | 78 | * \param args `printf` style format and arguments. |
46 | 79 | */ |
47 | | -#define log_info(args...) printf("INFO: " args) |
| 80 | +#define log_info(args...) log_(LOG_INFO, args) |
48 | 81 |
|
49 | 82 | /** Log a debugging message. |
50 | 83 | * \param args `printf` style format and arguments. |
51 | 84 | */ |
52 | 85 | #define log_debug(args...) \ |
53 | 86 | do { \ |
54 | 87 | if (DEBUG) { \ |
55 | | - printf("DEBUG: " args); \ |
| 88 | + log_(LOG_DEBUG, args); \ |
56 | 89 | } \ |
57 | 90 | } while (0) |
58 | 91 |
|
|
0 commit comments