summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 7fff2a4)
raw | patch | inline | side by side (parent: 7fff2a4)
author | Sebastian Harl <sh@tokkee.org> | |
Sat, 20 Jul 2013 00:06:35 +0000 (17:06 -0700) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Sat, 20 Jul 2013 00:06:35 +0000 (17:06 -0700) |
src/core/plugin.c | patch | blob | history | |
src/include/core/plugin.h | patch | blob | history |
diff --git a/src/core/plugin.c b/src/core/plugin.c
index 0a69bff2364a50e2b7566e4f4d0c4aaa6ec5b74c..c248d37eff6c15f9abce00d3d0b53b0b636a580e 100644 (file)
--- a/src/core/plugin.c
+++ b/src/core/plugin.c
#include "core/error.h"
#include "core/time.h"
#include "utils/llist.h"
+#include "utils/strbuf.h"
#include <assert.h>
sdb_llist_iter_t *iter;
int ret = -1;
+ if (! msg)
+ return 0;
+
if (! log_list)
return fprintf(stderr, "[%s] %s\n", SDB_LOG_PRIO_TO_STRING(prio), msg);
return ret;
} /* sdb_plugin_log */
+int
+sdb_plugin_vlogf(int prio, const char *fmt, va_list ap)
+{
+ sdb_strbuf_t *buf;
+ int ret;
+
+ if (! fmt)
+ return 0;
+
+ buf = sdb_strbuf_create(64);
+ if (! buf) {
+ ret = fprintf(stderr, "[%s] ", SDB_LOG_PRIO_TO_STRING(prio));
+ ret += vfprintf(stderr, fmt, ap);
+ return ret;
+ }
+
+ if (sdb_strbuf_vsprintf(buf, fmt, ap) < 0) {
+ sdb_strbuf_destroy(buf);
+ return -1;
+ }
+
+ ret = sdb_plugin_log(prio, sdb_strbuf_string(buf));
+ sdb_strbuf_destroy(buf);
+ return ret;
+} /* sdb_plugin_vlogf */
+
+int
+sdb_plugin_logf(int prio, const char *fmt, ...)
+{
+ va_list ap;
+ int ret;
+
+ if (! fmt)
+ return 0;
+
+ va_start(ap, fmt);
+ ret = sdb_plugin_vlogf(prio, fmt, ap);
+ va_end(ap);
+ return ret;
+} /* sdb_plugin_logf */
+
/* vim: set tw=78 sw=4 ts=4 noexpandtab : */
index 79a171ab16330ed047b2aef2afc043e8217f4d98..bef5e0b4ccb35251f261ff8af4defe54b898d2bf 100644 (file)
#include "liboconfig/oconfig.h"
+#include <stdarg.h>
+
#ifdef __cplusplus
extern "C" {
#endif
int
sdb_plugin_log(int prio, const char *msg);
+/*
+ * sdb_plugin_logf:
+ * Log a formatted message. See sdb_plugin_log for more information.
+ */
+int
+sdb_plugin_vlogf(int prio, const char *fmt, va_list ap);
+int
+sdb_plugin_logf(int prio, const char *fmt, ...);
+
#ifdef __cplusplus
} /* extern "C" */
#endif