| 1 |
#include "xh_config.h" |
| 2 |
#include "xh_core.h" |
| 3 |
|
| 4 |
#define XH_LOG_LEVEL XH_LOG_TRACE |
| 5 |
|
| 6 |
static char *LOG_LEVEL_NAME[7] = { |
| 7 |
"CRITIC", |
| 8 |
"ERROR", |
| 9 |
"WARN", |
| 10 |
"NOTICE", |
| 11 |
"INFO", |
| 12 |
"DEBUG", |
| 13 |
"TRACE", |
| 14 |
}; |
| 15 |
|
| 16 |
void |
| 17 |
xh_log(xh_log_level_t log_level, const char *func, xh_int_t line, const char *msg, ...) |
| 18 |
{ |
| 19 |
va_list args; |
| 20 |
|
| 21 |
if (log_level > XH_LOG_LEVEL) return; |
| 22 |
|
| 23 |
(void) fprintf(stderr, "(%s) %s[%.0d]: ", LOG_LEVEL_NAME[log_level], func, (int) line); |
| 24 |
|
| 25 |
va_start(args, msg); |
| 26 |
(void) vfprintf(stderr, msg, args); |
| 27 |
if (msg[strlen(msg) - 1] != '\n') { |
| 28 |
(void) fprintf(stderr, "\n"); |
| 29 |
} |
| 30 |
va_end(args); |
| 31 |
} |