Code

plugin: Ignore internal loggers when checking for existing loggers.
authorSebastian Harl <sh@tokkee.org>
Wed, 25 Jun 2014 21:12:44 +0000 (23:12 +0200)
committerSebastian Harl <sh@tokkee.org>
Wed, 25 Jun 2014 21:12:44 +0000 (23:12 +0200)
An internal logger may currently be registered by the frontend which uses it
to send log messages to a client. Usually, these internal loggers will not
actually log stuff. Thus, we'll have to ignore them when deciding about
fallbacks.

src/core/plugin.c

index 8cd490a22a7da2f39e946f4d06be445fda1ebba7..b3d5973178dffed19411af5d5acea45a99b718e3 100644 (file)
@@ -1113,12 +1113,11 @@ sdb_plugin_log(int prio, const char *msg)
        sdb_llist_iter_t *iter;
        int ret = -1;
 
+       _Bool logged = 0;
+
        if (! msg)
                return 0;
 
-       if (! sdb_llist_len(log_list))
-               return fprintf(stderr, "[%s] %s\n", SDB_LOG_PRIO_TO_STRING(prio), msg);
-
        iter = sdb_llist_get_iter(log_list);
        while (sdb_llist_iter_has_next(iter)) {
                sdb_plugin_log_cb callback;
@@ -1131,8 +1130,15 @@ sdb_plugin_log(int prio, const char *msg)
                tmp = callback(prio, msg, SDB_PLUGIN_CB(obj)->cb_user_data);
                if (tmp > ret)
                        ret = tmp;
+
+               if (SDB_PLUGIN_CB(obj)->cb_ctx)
+                       logged = 1;
+               /* else: this is an internally registered callback */
        }
        sdb_llist_iter_destroy(iter);
+
+       if (! logged)
+               return fprintf(stderr, "[%s] %s\n", SDB_LOG_PRIO_TO_STRING(prio), msg);
        return ret;
 } /* sdb_plugin_log */