[vlc-commits] journal: add native logger module for the SystemD Journal
Rémi Denis-Courmont
git at videolan.org
Sun Feb 8 13:57:22 CET 2015
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun Feb 8 14:55:37 2015 +0200| [15ed09825868776d03e5891a922b28edd9d61f4b] | committer: Rémi Denis-Courmont
journal: add native logger module for the SystemD Journal
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=15ed09825868776d03e5891a922b28edd9d61f4b
---
NEWS | 1 +
configure.ac | 10 ++++++
modules/logger/Makefile.am | 7 ++++
modules/logger/journal.c | 86 ++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 104 insertions(+)
diff --git a/NEWS b/NEWS
index 216dd14..815cb5e 100644
--- a/NEWS
+++ b/NEWS
@@ -93,6 +93,7 @@ libVLC:
identifier (if there is one available)
Logging
+ * Support for the SystemD Journal
* Use --syslog and --syslog-debug command line options to include debug
messages in syslog. With --syslog, errors and warnings will be sent only.
diff --git a/configure.ac b/configure.ac
index 6431951..2fcbd4c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -868,6 +868,16 @@ AS_IF([test "${enable_dbus}" != "no"], [
])
AM_CONDITIONAL([HAVE_DBUS], [test "${have_dbus}" = "yes"])
+
+dnl Check for systemd
+PKG_CHECK_MODULES([SYSTEMD], [libsystemd], [
+ have_systemd="yes"
+], [
+ AC_MSG_WARN([${SYSTEMD_PKG_ERRORS}.])
+])
+AM_CONDITIONAL([HAVE_SYSTEMD], [test "${have_systemd}" = "yes"])
+
+
dnl Check for ntohl, etc.
VLC_SAVE_FLAGS
CFLAGS="${CFLAGS} -Wall -Werror"
diff --git a/modules/logger/Makefile.am b/modules/logger/Makefile.am
index 0cd2a2c..54c924f 100644
--- a/modules/logger/Makefile.am
+++ b/modules/logger/Makefile.am
@@ -7,3 +7,10 @@ libsyslog_plugin_la_SOURCES = logger/syslog.c
if HAVE_SYSLOG
logger_LTLIBRARIES += libsyslog_plugin.la
endif
+
+libsd_journal_plugin_la_SOURCES = logger/journal.c
+libsd_journal_plugin_la_CPPFLAGS = $(AM_CPPFLAGS) $(SYSTEMD_CFLAGS)
+libsd_journal_plugin_la_LIBADD = $(SYSTEMD_LIBS)
+if HAVE_SYSTEMD
+logger_LTLIBRARIES += libsd_journal_plugin.la
+endif
diff --git a/modules/logger/journal.c b/modules/logger/journal.c
new file mode 100644
index 0000000..b7a69e3
--- /dev/null
+++ b/modules/logger/journal.c
@@ -0,0 +1,86 @@
+/*****************************************************************************
+ * journal.c: SystemD journal logger plugin
+ *****************************************************************************
+ * Copyright © 2015 Rémi Denis-Courmont
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <stdarg.h>
+#include <inttypes.h>
+#include <syslog.h>
+#include <systemd/sd-journal.h>
+
+#include <vlc_common.h>
+#include <vlc_plugin.h>
+
+static const int priorities[4] = {
+ [VLC_MSG_INFO] = LOG_INFO,
+ [VLC_MSG_ERR] = LOG_ERR,
+ [VLC_MSG_WARN] = LOG_WARNING,
+ [VLC_MSG_DBG] = LOG_DEBUG,
+};
+
+static void Log(void *opaque, int type, const vlc_log_t *meta,
+ const char *format, va_list ap)
+{
+ static const char default_msg[] = "message lost";
+ char *msg;
+ int canc = vlc_savecancel();
+
+ if (vasprintf(&msg, format, ap) == -1)
+ msg = (char *)default_msg;
+
+ sd_journal_send("MESSAGE=%s", msg,
+ "PRIORITY=%d", priorities[type],
+ "CODE_FILE=%s", (meta->file != NULL) ? meta->file : "",
+ "CODE_LINE=%u", meta->line,
+ "CODE_FUNC=%s", (meta->func != NULL) ? meta->func : "",
+ //"ERRNO=%d"
+ "VLC_OBJECT_ID=%"PRIxPTR, meta->i_object_id,
+ "VLC_OBJECT_TYPE=%s", meta->psz_object_type,
+ "VLC_MODULE=%s", meta->psz_module,
+ "VLC_HEADER=%s", (meta->psz_header != NULL) ? meta->psz_header : "",
+ NULL);
+
+ vlc_restorecancel(canc);
+
+ if (msg != default_msg)
+ free(msg);
+ (void) opaque;
+}
+
+static vlc_log_cb Open(vlc_object_t *obj, void **sysp)
+{
+ if (!var_InheritBool(obj, "syslog"))
+ return NULL;
+
+ (void) sysp;
+ return Log;
+}
+
+vlc_module_begin()
+ set_shortname(N_("Journal"))
+ set_description(N_("SystemD journal logger"))
+ set_category(CAT_ADVANCED)
+ set_subcategory(SUBCAT_ADVANCED_MISC)
+ set_capability("logger", 30)
+ set_callbacks(Open, NULL)
+ add_shortcut("journal")
+vlc_module_end()
More information about the vlc-commits
mailing list