X-Git-Url: https://git.tokkee.org/?p=sysdb.git;a=blobdiff_plain;f=src%2Futils%2Ferror.c;h=f40e31ada656f24e4719783bbe279cf49cfb7be2;hp=5b9b448deefc4737c7e812e828d3a9fdd041f5a2;hb=56b97a180a53aecbfe9f7162b8ece3faae973cf9;hpb=ddb933096618a6bceded29e4dc2b37cb72134366 diff --git a/src/utils/error.c b/src/utils/error.c index 5b9b448..f40e31a 100644 --- a/src/utils/error.c +++ b/src/utils/error.c @@ -25,7 +25,10 @@ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "core/plugin.h" +#if HAVE_CONFIG_H +# include "config.h" +#endif /* HAVE_CONFIG_H */ + #include "utils/error.h" #include "utils/strbuf.h" @@ -57,6 +60,8 @@ static sdb_error_ctx_t default_error_ctx = SDB_ERROR_INIT; static pthread_key_t error_ctx_key; static _Bool error_ctx_key_initialized = 0; +static int (*logger)(int prio, const char *msg) = NULL; + /* * private helper functions */ @@ -163,7 +168,12 @@ sdb_do_log(int prio) if (ctx->logged) return 0; - ret = sdb_plugin_log(prio, sdb_strbuf_string(ctx->msg)); + if (logger) + ret = logger(prio, sdb_strbuf_string(ctx->msg)); + else + ret = fprintf(stderr, "[%s] %s\n", SDB_LOG_PRIO_TO_STRING(prio), + sdb_strbuf_string(ctx->msg)); + ctx->logged = 1; return ret; } /* sdb_do_log */ @@ -172,6 +182,12 @@ sdb_do_log(int prio) * public API */ +void +sdb_error_set_logger(int (*f)(int, const char *)) +{ + logger = f; +} /* sdb_error_set_logger */ + int sdb_log(int prio, const char *fmt, ...) {