summaryrefslogtreecommitdiff
path: root/log.c
diff options
context:
space:
mode:
authorUwe Hermann <uwe@hermann-uwe.de>2012-01-25 11:00:04 +0100
committerUwe Hermann <uwe@hermann-uwe.de>2012-01-26 01:03:54 +0100
commit3a8b2e789262545fe409f95f69319b80e66aac13 (patch)
tree76559581c17a42539d38898ad6dff2f6706be001 /log.c
parentac941bf91b1a4f75ed793ca1547a1bd75bac0a1a (diff)
downloadlibsigrokdecode-3a8b2e789262545fe409f95f69319b80e66aac13.tar.gz
libsigrokdecode-3a8b2e789262545fe409f95f69319b80e66aac13.zip
srd: log: Support for setting a log domain (prefix).
Diffstat (limited to 'log.c')
-rw-r--r--log.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/log.c b/log.c
index a2633f4..c7fe76f 100644
--- a/log.c
+++ b/log.c
@@ -38,6 +38,11 @@ static srd_log_handler_t srd_handler = srd_logv;
*/
static void *srd_handler_data = NULL;
+/* Log domain (a short string that is used as prefix for all messages). */
+#define LOGDOMAIN_MAXLEN 30
+#define LOGDOMAIN_DEFAULT "srd: "
+static char srd_log_domain[LOGDOMAIN_MAXLEN + 1] = LOGDOMAIN_DEFAULT;
+
/**
* Set the libsigrokdecode loglevel.
*
@@ -74,6 +79,37 @@ int srd_get_loglevel(void)
}
/**
+ * TODO.
+ *
+ * @param logdomain TODO
+ * @return TODO.
+ */
+int srd_log_set_logdomain(const char *logdomain)
+{
+ if (!logdomain) {
+ srd_err("log: %s: logdomain was NULL", __func__);
+ return SRD_ERR_ARG;
+ }
+
+ /* TODO: Error handling. */
+ snprintf((char *)&srd_log_domain, LOGDOMAIN_MAXLEN, "%s", logdomain);
+
+ srd_dbg("log domain set to '%s'", (const char *)&srd_log_domain);
+
+ return SRD_OK;
+}
+
+/**
+ * TODO.
+ *
+ * @return TODO.
+ */
+char *srd_log_get_logdomain(void)
+{
+ return g_strdup((char *)srd_log_domain);
+}
+
+/**
* Set the libsigrokdecode log handler to the specified function.
*
* @param handler Function pointer to the log handler function to use.
@@ -129,6 +165,8 @@ static int srd_logv(void *data, int loglevel, const char *format, va_list args)
if (loglevel > srd_loglevel)
return SRD_OK; /* TODO? */
+ if (srd_log_domain[0] != '\0')
+ fprintf(stderr, srd_log_domain);
ret = vfprintf(stderr, format, args);
fprintf(stderr, "\n");