diff options
author | Suren A. Chilingaryan <csa@suren.me> | 2015-04-29 03:42:43 +0200 |
---|---|---|
committer | Suren A. Chilingaryan <csa@suren.me> | 2015-04-29 03:42:43 +0200 |
commit | bf466a54a10293067765bf767c572cbf09bcd170 (patch) | |
tree | 7b285a15aa71949dceb17b8726717ca3e003bee1 /pcilib/error.c | |
parent | c95fc0fb80a5e72cf198e77c9bf64fd17286dfde (diff) | |
download | pcitool-bf466a54a10293067765bf767c572cbf09bcd170.tar.gz pcitool-bf466a54a10293067765bf767c572cbf09bcd170.tar.bz2 pcitool-bf466a54a10293067765bf767c572cbf09bcd170.tar.xz pcitool-bf466a54a10293067765bf767c572cbf09bcd170.zip |
New error reporting public interface
Diffstat (limited to 'pcilib/error.c')
-rw-r--r-- | pcilib/error.c | 36 |
1 files changed, 25 insertions, 11 deletions
diff --git a/pcilib/error.c b/pcilib/error.c index 9df7d9d..538534b 100644 --- a/pcilib/error.c +++ b/pcilib/error.c @@ -1,24 +1,38 @@ #include <stdio.h> +#include <stdlib.h> #include <stdarg.h> #include "export.h" #include "error.h" -void pcilib_print_error(const char *msg, ...) { - va_list va; - - va_start(va, msg); +void pcilib_print_error(void *arg, const char *file, int line, pcilib_log_priority_t prio, const char *msg, va_list va) { vprintf(msg, va); - va_end(va); - printf("\n"); + printf(" [%s:%d]\n", file, line); } +static void *pcilib_logger_argument = NULL; +static pcilib_log_priority_t pcilib_logger_min_prio = PCILIB_LOG_WARNING; +static pcilib_logger_t pcilib_logger = pcilib_print_error; + + + +void pcilib_log_message(const char *file, int line, pcilib_log_priority_t prio, const char *msg, ...) { + va_list va; + + if (prio >= pcilib_logger_min_prio) { + va_start(va, msg); + pcilib_logger(pcilib_logger_argument, file, line, prio, msg, va); + va_end(va); + } +} + + +int pcilib_set_logger(pcilib_log_priority_t min_prio, pcilib_logger_t logger, void *arg) { + pcilib_logger_min_prio = min_prio; + pcilib_logger_argument = arg; -int pcilib_set_error_handler(void (*err)(const char *msg, ...), void (*warn)(const char *msg, ...)) { - if (err) pcilib_error = err; - else pcilib_error = pcilib_print_error; - if (warn) pcilib_warning = warn; - else pcilib_warning = pcilib_print_error; + if (logger) pcilib_logger = logger; + else logger = pcilib_print_error; return 0; } |