X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Futils%2Ferror.c;h=f40e31ada656f24e4719783bbe279cf49cfb7be2;hb=4fd156c45f4875aad3a12123e67082de33908bc4;hp=c62b20d5c6c6f22c2230b21320f2fae93a9bd5d8;hpb=50d3819344ff132e043ba95da7915092d03baf6a;p=sysdb.git diff --git a/src/utils/error.c b/src/utils/error.c index c62b20d..f40e31a 100644 --- a/src/utils/error.c +++ b/src/utils/error.c @@ -25,6 +25,10 @@ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#if HAVE_CONFIG_H +# include "config.h" +#endif /* HAVE_CONFIG_H */ + #include "utils/error.h" #include "utils/strbuf.h" @@ -56,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 */ @@ -162,9 +168,12 @@ sdb_do_log(int prio) if (ctx->logged) return 0; - ret = fprintf(stderr, "[%s] %s\n", - SDB_LOG_PRIO_TO_STRING(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 */ @@ -173,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, ...) {