#include "lib/zlog_5424.h"
#include "lib/lib_errors.h"
#include "lib/printfrr.h"
+#include "lib/systemd.h"
#ifndef VTYSH_EXTRACT_PL
#include "lib/log_vty_clippy.c"
static struct zlog_cfg_file zt_file = {
.prio_min = ZLOG_DISABLED,
};
-static struct zlog_cfg_file zt_stdout = {
- .prio_min = ZLOG_DISABLED,
-};
static struct zlog_cfg_filterfile zt_filterfile = {
.parent = {
.prio_min = ZLOG_DISABLED,
},
};
+static struct zlog_cfg_file zt_stdout_file = {
+ .prio_min = ZLOG_DISABLED,
+};
+static struct zlog_cfg_5424 zt_stdout_journald = {
+ .prio_min = ZLOG_DISABLED,
+
+ .fmt = ZLOG_FMT_JOURNALD,
+ .dst = ZLOG_5424_DST_UNIX,
+ .filename = "/run/systemd/journal/socket",
+
+ /* this can't be changed through config since this target substitutes
+ * in for the "plain" stdout target
+ */
+ .facility = LOG_DAEMON,
+ .kw_version = false,
+ .kw_location = true,
+ .kw_uid = true,
+ .kw_ec = true,
+ .kw_args = true,
+};
+static bool stdout_journald_in_use;
+
const char *zlog_progname;
static const char *zlog_protoname;
SHOW_STR
"Show current logging configuration\n")
{
+ int stdout_prio;
+
log_show_syslog(vty);
+ stdout_prio = stdout_journald_in_use ? zt_stdout_journald.prio_min
+ : zt_stdout_file.prio_min;
+
vty_out(vty, "Stdout logging: ");
- if (zt_stdout.prio_min == ZLOG_DISABLED)
+ if (stdout_prio == ZLOG_DISABLED)
vty_out(vty, "disabled");
else
- vty_out(vty, "level %s",
- zlog_priority[zt_stdout.prio_min]);
+ vty_out(vty, "level %s", zlog_priority[stdout_prio]);
vty_out(vty, "\n");
vty_out(vty, "File logging: ");
return CMD_SUCCESS;
}
+static void log_stdout_apply_level(void)
+{
+ int maxlvl;
+
+ maxlvl = ZLOG_MAXLVL(log_config_stdout_lvl, log_cmdline_stdout_lvl);
+
+ if (stdout_journald_in_use) {
+ zt_stdout_journald.prio_min = maxlvl;
+ zlog_5424_apply_meta(&zt_stdout_journald);
+ } else {
+ zt_stdout_file.prio_min = maxlvl;
+ zlog_file_set_other(&zt_stdout_file);
+ }
+}
+
DEFPY (config_log_stdout,
config_log_stdout_cmd,
"log stdout [<emergencies|alerts|critical|errors|warnings|notifications|informational|debugging>$levelarg]",
level = log_default_lvl;
log_config_stdout_lvl = level;
- zt_stdout.prio_min = ZLOG_MAXLVL(log_config_stdout_lvl,
- log_cmdline_stdout_lvl);
- zlog_file_set_other(&zt_stdout);
+ log_stdout_apply_level();
return CMD_SUCCESS;
}
LOG_LEVEL_DESC)
{
log_config_stdout_lvl = ZLOG_DISABLED;
- zt_stdout.prio_min = ZLOG_MAXLVL(log_config_stdout_lvl,
- log_cmdline_stdout_lvl);
- zlog_file_set_other(&zt_stdout);
+ log_stdout_apply_level();
return CMD_SUCCESS;
}
if (strcmp(type, "stdout") == 0) {
log_cmdline_stdout_lvl = nlevel;
- zt_stdout.prio_min = ZLOG_MAXLVL(log_config_stdout_lvl,
- log_cmdline_stdout_lvl);
- zlog_file_set_other(&zt_stdout);
+ log_stdout_apply_level();
return;
}
if (strcmp(type, "syslog") == 0) {
log_cmdline_syslog_lvl));
log_cmdline_stdout_lvl = ZLOG_DISABLED;
- zt_stdout.prio_min = ZLOG_MAXLVL(log_config_stdout_lvl,
- log_cmdline_stdout_lvl);
- zlog_file_set_other(&zt_stdout);
+ log_stdout_apply_level();
return CMD_SUCCESS;
}
{
zt_file.record_priority = true;
zlog_file_set_other(&zt_file);
- zt_stdout.record_priority = true;
- zlog_file_set_other(&zt_stdout);
+ if (!stdout_journald_in_use) {
+ zt_stdout_file.record_priority = true;
+ zlog_file_set_other(&zt_stdout_file);
+ }
zt_filterfile.parent.record_priority = true;
zlog_file_set_other(&zt_filterfile.parent);
return CMD_SUCCESS;
{
zt_file.record_priority = false;
zlog_file_set_other(&zt_file);
- zt_stdout.record_priority = false;
- zlog_file_set_other(&zt_stdout);
+ if (!stdout_journald_in_use) {
+ zt_stdout_file.record_priority = false;
+ zlog_file_set_other(&zt_stdout_file);
+ }
zt_filterfile.parent.record_priority = false;
zlog_file_set_other(&zt_filterfile.parent);
return CMD_SUCCESS;
{
zt_file.ts_subsec = precision;
zlog_file_set_other(&zt_file);
- zt_stdout.ts_subsec = precision;
- zlog_file_set_other(&zt_stdout);
+ if (!stdout_journald_in_use) {
+ zt_stdout_file.ts_subsec = precision;
+ zlog_file_set_other(&zt_stdout_file);
+ }
zt_filterfile.parent.ts_subsec = precision;
zlog_file_set_other(&zt_filterfile.parent);
return CMD_SUCCESS;
{
zt_file.ts_subsec = 0;
zlog_file_set_other(&zt_file);
- zt_stdout.ts_subsec = 0;
- zlog_file_set_other(&zt_stdout);
+ if (!stdout_journald_in_use) {
+ zt_stdout_file.ts_subsec = 0;
+ zlog_file_set_other(&zt_stdout_file);
+ }
zt_filterfile.parent.ts_subsec = 0;
zlog_file_set_other(&zt_filterfile.parent);
return CMD_SUCCESS;
zlog_filterfile_init(&zt_filterfile);
- zlog_file_set_fd(&zt_stdout, STDOUT_FILENO);
+ if (sd_stdout_is_journal) {
+ stdout_journald_in_use = true;
+ zlog_5424_init(&zt_stdout_journald);
+ zlog_5424_apply_dst(&zt_stdout_journald);
+ } else
+ zlog_file_set_fd(&zt_stdout_file, STDOUT_FILENO);
return 0;
}