diff options
author | Jakub Hrozek <jhrozek@redhat.com> | 2013-09-05 06:52:15 +0200 |
---|---|---|
committer | Jakub Hrozek <jhrozek@redhat.com> | 2013-09-18 18:56:40 +0200 |
commit | 77c0d1f6074059dafd2293f9c42ea0f9d60f8aad (patch) | |
tree | 4a6c5fcc27adb75a0dd84464fbf1ab0ffc183c1c /src/util | |
parent | 11a044514e3799c4e685cf98ed5c058aa02b5fdb (diff) | |
download | sssd-77c0d1f6074059dafd2293f9c42ea0f9d60f8aad.tar.gz sssd-77c0d1f6074059dafd2293f9c42ea0f9d60f8aad.tar.xz sssd-77c0d1f6074059dafd2293f9c42ea0f9d60f8aad.zip |
Add journald support
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/sss_log.c | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/util/sss_log.c b/src/util/sss_log.c index 45e883109..6b78c9d4b 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 <systemd/sd-journal.h> +#else /* WITH_JOURNALD */ #include <syslog.h> +#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 */ |