1 /*****************************************************************************
2 * journal.c: SystemD journal logger plugin
3 *****************************************************************************
4 * Copyright © 2015 Rémi Denis-Courmont
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation; either version 2.1 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
19 *****************************************************************************/
28 #include <systemd/sd-journal.h>
30 #include <vlc_common.h>
31 #include <vlc_plugin.h>
33 static const int priorities[4] = {
34 [VLC_MSG_INFO] = LOG_INFO,
35 [VLC_MSG_ERR] = LOG_ERR,
36 [VLC_MSG_WARN] = LOG_WARNING,
37 [VLC_MSG_DBG] = LOG_DEBUG,
40 static void Log(void *opaque, int type, const vlc_log_t *meta,
41 const char *format, va_list ap)
43 static const char default_msg[] = "message lost";
45 int canc = vlc_savecancel();
47 if (vasprintf(&msg, format, ap) == -1)
48 msg = (char *)default_msg;
50 sd_journal_send("MESSAGE=%s", msg,
51 "PRIORITY=%d", priorities[type],
52 "CODE_FILE=%s", (meta->file != NULL) ? meta->file : "",
53 "CODE_LINE=%u", meta->line,
54 "CODE_FUNC=%s", (meta->func != NULL) ? meta->func : "",
56 "VLC_OBJECT_ID=%"PRIxPTR, meta->i_object_id,
57 "VLC_OBJECT_TYPE=%s", meta->psz_object_type,
58 "VLC_MODULE=%s", meta->psz_module,
59 "VLC_HEADER=%s", (meta->psz_header != NULL) ? meta->psz_header : "",
62 vlc_restorecancel(canc);
64 if (msg != default_msg)
69 static vlc_log_cb Open(vlc_object_t *obj, void **sysp)
71 if (!var_InheritBool(obj, "syslog"))
79 set_shortname(N_("Journal"))
80 set_description(N_("SystemD journal logger"))
81 set_category(CAT_ADVANCED)
82 set_subcategory(SUBCAT_ADVANCED_MISC)
83 set_capability("logger", 30)
84 set_callbacks(Open, NULL)
85 add_shortcut("journal")