summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: ddb9330)
raw | patch | inline | side by side (parent: ddb9330)
author | Sebastian Harl <sh@tokkee.org> | |
Tue, 10 Dec 2013 18:13:37 +0000 (19:13 +0100) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Tue, 10 Dec 2013 18:13:37 +0000 (19:13 +0100) |
Don't depend on the plugin module anymore. Rather, add sdb_error_set_logger()
which may be used to set a callback to be used for all logging. Default to
printing to stderr.
sysdbd now uses that to register sdb_plugin_log as logger callback.
which may be used to set a callback to be used for all logging. Default to
printing to stderr.
sysdbd now uses that to register sdb_plugin_log as logger callback.
src/daemon/sysdbd.c | patch | blob | history | |
src/include/utils/error.h | patch | blob | history | |
src/utils/error.c | patch | blob | history |
diff --git a/src/daemon/sysdbd.c b/src/daemon/sysdbd.c
index 6952c1ce7df5a85ab5a12804acef8f3900221b4a..21350f308b15bc75d624baed8f99b878011caf5c 100644 (file)
--- a/src/daemon/sysdbd.c
+++ b/src/daemon/sysdbd.c
struct sigaction sa_intterm;
int status;
+ sdb_error_set_logger(sdb_plugin_log);
+
while (42) {
int opt = getopt(argc, argv, "C:DhV");
index aaa288c33c3e51f2e12bbaa8252196ee51480d0a..e170a7d5e85109406a15af21d4247daa27cd0083 100644 (file)
: ((prio) == SDB_LOG_INFO) ? "INFO" \
: ((prio) == SDB_LOG_DEBUG) ? "DEBUG" : "UNKNOWN")
+/*
+ * sdb_error_set_logger:
+ * Set the logging callback to be used for logging messages. By default (or
+ * when explicitely setting the logger to NULL), logs will be written to the
+ * stderr channel.
+ */
+void
+sdb_error_set_logger(int (*f)(int, const char *));
+
/*
* sdb_log:
* Log the specified message. The string will be formatted in printf-style
diff --git a/src/utils/error.c b/src/utils/error.c
index 5b9b448deefc4737c7e812e828d3a9fdd041f5a2..6bf64c2a25983347142d8e591b9d1fcee67460b7 100644 (file)
--- a/src/utils/error.c
+++ b/src/utils/error.c
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include "core/plugin.h"
#include "utils/error.h"
#include "utils/strbuf.h"
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
*/
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 */
* 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, ...)
{