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";
46 if (vasprintf(&msg
, format
, ap
) == -1)
47 msg
= (char *)default_msg
;
49 sd_journal_send("MESSAGE=%s", msg
,
50 "PRIORITY=%d", priorities
[type
],
51 "CODE_FILE=%s", (meta
->file
!= NULL
) ? meta
->file
: "",
52 "CODE_LINE=%u", meta
->line
,
53 "CODE_FUNC=%s", (meta
->func
!= NULL
) ? meta
->func
: "",
55 "VLC_TID=%lu" /* change to OBJECT_TID if standardized */, meta
->tid
,
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 if (msg
!= default_msg
)
67 static vlc_log_cb
Open(vlc_object_t
*obj
, void **sysp
)
69 if (!var_InheritBool(obj
, "syslog"))
77 set_shortname(N_("Journal"))
78 set_description(N_("SystemD journal logger"))
79 set_category(CAT_ADVANCED
)
80 set_subcategory(SUBCAT_ADVANCED_MISC
)
81 set_capability("logger", 30)
82 set_callbacks(Open
, NULL
)
83 add_shortcut("journal")