From 77c0d1f6074059dafd2293f9c42ea0f9d60f8aad Mon Sep 17 00:00:00 2001 From: Jakub Hrozek Date: Thu, 5 Sep 2013 06:52:15 +0200 Subject: Add journald support --- src/util/sss_log.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'src/util') diff --git a/src/util/sss_log.c b/src/util/sss_log.c index 45e88310..6b78c9d4 100644 --- a/src/util/sss_log.c +++ b/src/util/sss_log.c @@ -23,7 +23,12 @@ */ #include "util/util.h" + +#ifdef WITH_JOURNALD +#include +#else /* WITH_JOURNALD */ #include +#endif /* WITH_JOURNALD */ static int sss_to_syslog(int priority) { @@ -52,6 +57,34 @@ static int sss_to_syslog(int priority) } } +#ifdef WITH_JOURNALD + +void sss_log(int priority, const char *format, ...) +{ + va_list ap; + int syslog_priority; + int ret; + char *message; + + va_start(ap, format); + ret = vasprintf(&message, format, ap); + va_end(ap); + + if (ret == -1) { + /* ENOMEM */ + return; + } + + syslog_priority = sss_to_syslog(priority); + sd_journal_send("MESSAGE=%s", message, + "PRIORITY=%i", syslog_priority, + "SYSLOG_FACILITY=%i", LOG_FAC(LOG_DAEMON), + "SYSLOG_IDENTIFIER=%s", debug_prg_name, + NULL); +} + +#else /* WITH_JOURNALD */ + void sss_log(int priority, const char *format, ...) { va_list ap; @@ -67,3 +100,5 @@ void sss_log(int priority, const char *format, ...) closelog(); } + +#endif /* WITH_JOURNALD */ -- cgit