summaryrefslogtreecommitdiff
path: root/src/util/sss_log.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/sss_log.c')
-rw-r--r--src/util/sss_log.c35
1 files changed, 35 insertions, 0 deletions
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 <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 */