3 * Copyright (C) 2019 Cumulus Networks, Inc.
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the Free
8 * Software Foundation; either version 2 of the License, or (at your option)
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 * You should have received a copy of the GNU General Public License along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 #include "lib/log_vty.h"
26 #include "lib/zlog_targets.h"
27 #include "lib/zlog_5424.h"
28 #include "lib/lib_errors.h"
29 #include "lib/printfrr.h"
30 #include "lib/systemd.h"
32 #include "lib/log_vty_clippy.c"
34 #define ZLOG_MAXLVL(a, b) MAX(a, b)
36 DEFINE_HOOK(zlog_rotate
, (), ());
37 DEFINE_HOOK(zlog_cli_show
, (struct vty
* vty
), (vty
));
39 static unsigned logmsgs_with_persist_bt
;
41 static const int log_default_lvl
= LOG_DEBUG
;
43 static int log_config_stdout_lvl
= ZLOG_DISABLED
;
44 static int log_config_syslog_lvl
= ZLOG_DISABLED
;
45 static int log_cmdline_stdout_lvl
= ZLOG_DISABLED
;
46 static int log_cmdline_syslog_lvl
= ZLOG_DISABLED
;
48 static struct zlog_cfg_file zt_file_cmdline
= {
49 .prio_min
= ZLOG_DISABLED
,
51 static struct zlog_cfg_file zt_file
= {
52 .prio_min
= ZLOG_DISABLED
,
54 static struct zlog_cfg_filterfile zt_filterfile
= {
56 .prio_min
= ZLOG_DISABLED
,
60 static struct zlog_cfg_file zt_stdout_file
= {
61 .prio_min
= ZLOG_DISABLED
,
63 static struct zlog_cfg_5424 zt_stdout_journald
= {
64 .prio_min
= ZLOG_DISABLED
,
66 .fmt
= ZLOG_FMT_JOURNALD
,
67 .dst
= ZLOG_5424_DST_UNIX
,
68 .filename
= "/run/systemd/journal/socket",
70 /* this can't be changed through config since this target substitutes
71 * in for the "plain" stdout target
73 .facility
= LOG_DAEMON
,
80 static bool stdout_journald_in_use
;
82 const char *zlog_progname
;
83 static const char *zlog_protoname
;
85 static const struct facility_map
{
89 } syslog_facilities
[] = {
90 {LOG_KERN
, "kern", 1},
91 {LOG_USER
, "user", 2},
92 {LOG_MAIL
, "mail", 1},
93 {LOG_DAEMON
, "daemon", 1},
94 {LOG_AUTH
, "auth", 1},
95 {LOG_SYSLOG
, "syslog", 1},
97 {LOG_NEWS
, "news", 1},
98 {LOG_UUCP
, "uucp", 2},
99 {LOG_CRON
, "cron", 1},
103 {LOG_LOCAL0
, "local0", 6},
104 {LOG_LOCAL1
, "local1", 6},
105 {LOG_LOCAL2
, "local2", 6},
106 {LOG_LOCAL3
, "local3", 6},
107 {LOG_LOCAL4
, "local4", 6},
108 {LOG_LOCAL5
, "local5", 6},
109 {LOG_LOCAL6
, "local6", 6},
110 {LOG_LOCAL7
, "local7", 6},
114 static const char * const zlog_priority
[] = {
115 "emergencies", "alerts", "critical", "errors", "warnings",
116 "notifications", "informational", "debugging", NULL
,
119 const char *zlog_priority_str(int priority
)
121 if (priority
> LOG_DEBUG
)
123 return zlog_priority
[priority
];
126 const char *facility_name(int facility
)
128 const struct facility_map
*fm
;
130 for (fm
= syslog_facilities
; fm
->name
; fm
++)
131 if (fm
->facility
== facility
)
136 int facility_match(const char *str
)
138 const struct facility_map
*fm
;
140 for (fm
= syslog_facilities
; fm
->name
; fm
++)
141 if (!strncmp(str
, fm
->name
, fm
->match
))
146 int log_level_match(const char *s
)
150 for (level
= 0; zlog_priority
[level
] != NULL
; level
++)
151 if (!strncmp(s
, zlog_priority
[level
], 2))
153 return ZLOG_DISABLED
;
156 void zlog_rotate(void)
158 zlog_file_rotate(&zt_file
);
159 zlog_file_rotate(&zt_filterfile
.parent
);
160 zlog_file_rotate(&zt_file_cmdline
);
161 hook_call(zlog_rotate
);
165 void log_show_syslog(struct vty
*vty
)
167 int level
= zlog_syslog_get_prio_min();
169 vty_out(vty
, "Syslog logging: ");
170 if (level
== ZLOG_DISABLED
)
171 vty_out(vty
, "disabled\n");
173 vty_out(vty
, "level %s, facility %s, ident %s\n",
174 zlog_priority
[level
],
175 facility_name(zlog_syslog_get_facility()),
179 DEFUN_NOSH (show_logging
,
183 "Show current logging configuration\n")
187 log_show_syslog(vty
);
189 stdout_prio
= stdout_journald_in_use
? zt_stdout_journald
.prio_min
190 : zt_stdout_file
.prio_min
;
192 vty_out(vty
, "Stdout logging: ");
193 if (stdout_prio
== ZLOG_DISABLED
)
194 vty_out(vty
, "disabled");
196 vty_out(vty
, "level %s", zlog_priority
[stdout_prio
]);
199 vty_out(vty
, "File logging: ");
200 if (zt_file
.prio_min
== ZLOG_DISABLED
|| !zt_file
.filename
)
201 vty_out(vty
, "disabled");
203 vty_out(vty
, "level %s, filename %s",
204 zlog_priority
[zt_file
.prio_min
], zt_file
.filename
);
207 if (zt_filterfile
.parent
.prio_min
!= ZLOG_DISABLED
208 && zt_filterfile
.parent
.filename
)
209 vty_out(vty
, "Filtered-file logging: level %s, filename %s\n",
210 zlog_priority
[zt_filterfile
.parent
.prio_min
],
211 zt_filterfile
.parent
.filename
);
213 if (log_cmdline_syslog_lvl
!= ZLOG_DISABLED
)
215 "From command line: \"--log syslog --log-level %s\"\n",
216 zlog_priority
[log_cmdline_syslog_lvl
]);
217 if (log_cmdline_stdout_lvl
!= ZLOG_DISABLED
)
219 "From command line: \"--log stdout --log-level %s\"\n",
220 zlog_priority
[log_cmdline_stdout_lvl
]);
221 if (zt_file_cmdline
.prio_min
!= ZLOG_DISABLED
)
223 "From command line: \"--log file:%s --log-level %s\"\n",
224 zt_file_cmdline
.filename
,
225 zlog_priority
[zt_file_cmdline
.prio_min
]);
227 vty_out(vty
, "Protocol name: %s\n", zlog_protoname
);
228 vty_out(vty
, "Record priority: %s\n",
229 (zt_file
.record_priority
? "enabled" : "disabled"));
230 vty_out(vty
, "Timestamp precision: %d\n", zt_file
.ts_subsec
);
232 hook_call(zlog_cli_show
, vty
);
236 static void log_stdout_apply_level(void)
240 maxlvl
= ZLOG_MAXLVL(log_config_stdout_lvl
, log_cmdline_stdout_lvl
);
242 if (stdout_journald_in_use
) {
243 zt_stdout_journald
.prio_min
= maxlvl
;
244 zlog_5424_apply_meta(&zt_stdout_journald
);
246 zt_stdout_file
.prio_min
= maxlvl
;
247 zlog_file_set_other(&zt_stdout_file
);
251 DEFPY (config_log_stdout
,
252 config_log_stdout_cmd
,
253 "log stdout [<emergencies|alerts|critical|errors|warnings|notifications|informational|debugging>$levelarg]",
255 "Set stdout logging level\n"
261 level
= log_level_match(levelarg
);
262 if (level
== ZLOG_DISABLED
)
263 return CMD_ERR_NO_MATCH
;
265 level
= log_default_lvl
;
267 log_config_stdout_lvl
= level
;
268 log_stdout_apply_level();
272 DEFUN (no_config_log_stdout
,
273 no_config_log_stdout_cmd
,
274 "no log stdout [<emergencies|alerts|critical|errors|warnings|notifications|informational|debugging>]",
277 "Cancel logging to stdout\n"
280 log_config_stdout_lvl
= ZLOG_DISABLED
;
281 log_stdout_apply_level();
285 DEFUN_HIDDEN (config_log_monitor
,
286 config_log_monitor_cmd
,
287 "log monitor [<emergencies|alerts|critical|errors|warnings|notifications|informational|debugging>]",
289 "Set terminal line (monitor) logging level\n"
292 vty_out(vty
, "%% \"log monitor\" is deprecated and does nothing.\n");
296 DEFUN_HIDDEN (no_config_log_monitor
,
297 no_config_log_monitor_cmd
,
298 "no log monitor [<emergencies|alerts|critical|errors|warnings|notifications|informational|debugging>]",
301 "Disable terminal line (monitor) logging\n"
307 DEFPY_NOSH (debug_uid_backtrace
,
308 debug_uid_backtrace_cmd
,
309 "[no] debug unique-id UID backtrace",
312 "Options per individual log message, by unique ID\n"
313 "Log message unique ID (XXXXX-XXXXX)\n"
314 "Add backtrace to log when message is printed\n")
316 struct xrefdata search
, *xrd
;
317 struct xrefdata_logmsg
*xrdl
;
320 strlcpy(search
.uid
, uid
, sizeof(search
.uid
));
321 xrd
= xrefdata_uid_find(&xrefdata_uid
, &search
);
324 return CMD_ERR_NOTHING_TODO
;
326 if (xrd
->xref
->type
!= XREFT_LOGMSG
) {
327 vty_out(vty
, "%% ID \"%s\" is not a log message\n", uid
);
330 xrdl
= container_of(xrd
, struct xrefdata_logmsg
, xrefdata
);
332 flag
= (vty
->node
== CONFIG_NODE
) ? LOGMSG_FLAG_PERSISTENT
333 : LOGMSG_FLAG_EPHEMERAL
;
335 if ((xrdl
->fl_print_bt
& flag
) == (no
? 0 : flag
))
337 if (flag
== LOGMSG_FLAG_PERSISTENT
)
338 logmsgs_with_persist_bt
+= no
? -1 : 1;
340 xrdl
->fl_print_bt
^= flag
;
344 static int set_log_file(struct zlog_cfg_file
*target
, struct vty
*vty
,
345 const char *fname
, int loglevel
)
347 char path
[MAXPATHLEN
+ 1];
348 const char *fullpath
;
352 /* Path detection. */
353 if (!IS_DIRECTORY_SEP(*fname
)) {
354 char cwd
[MAXPATHLEN
+ 1];
356 cwd
[MAXPATHLEN
] = '\0';
358 if (getcwd(cwd
, MAXPATHLEN
) == NULL
) {
359 flog_err_sys(EC_LIB_SYSTEM_CALL
,
360 "config_log_file: Unable to alloc mem!");
361 return CMD_WARNING_CONFIG_FAILED
;
364 int pr
= snprintf(path
, sizeof(path
), "%s/%s", cwd
, fname
);
365 if (pr
< 0 || (unsigned int)pr
>= sizeof(path
)) {
368 "%s: Path too long ('%s/%s'); system maximum is %u",
369 __func__
, cwd
, fname
, MAXPATHLEN
);
370 return CMD_WARNING_CONFIG_FAILED
;
377 target
->prio_min
= loglevel
;
378 ok
= zlog_file_set_filename(target
, fullpath
);
382 vty_out(vty
, "can't open logfile %s\n", fname
);
383 return CMD_WARNING_CONFIG_FAILED
;
388 void command_setup_early_logging(const char *dest
, const char *level
)
396 nlevel
= log_level_match(level
);
398 if (nlevel
== ZLOG_DISABLED
) {
399 fprintf(stderr
, "invalid log level \"%s\"\n", level
);
403 nlevel
= log_default_lvl
;
408 sep
= strchr(dest
, ':');
409 len
= sep
? (int)(sep
- dest
) : (int)strlen(dest
);
411 snprintfrr(type
, sizeof(type
), "%.*s", len
, dest
);
413 if (strcmp(type
, "stdout") == 0) {
414 log_cmdline_stdout_lvl
= nlevel
;
415 log_stdout_apply_level();
418 if (strcmp(type
, "syslog") == 0) {
419 log_cmdline_syslog_lvl
= nlevel
;
420 zlog_syslog_set_prio_min(ZLOG_MAXLVL(log_config_syslog_lvl
,
421 log_cmdline_syslog_lvl
));
424 if (strcmp(type
, "file") == 0 && sep
) {
426 set_log_file(&zt_file_cmdline
, NULL
, sep
, nlevel
);
429 if (strcmp(type
, "monitor") == 0 && sep
) {
430 struct zlog_live_cfg cfg
= {};
435 fd
= strtoul(sep
, &endp
, 10);
436 if (!*sep
|| *endp
) {
437 fprintf(stderr
, "invalid monitor fd \"%s\"\n", sep
);
441 zlog_live_open_fd(&cfg
, nlevel
, fd
);
442 zlog_live_disown(&cfg
);
446 fprintf(stderr
, "invalid log target \"%s\" (\"%s\")\n", type
, dest
);
450 DEFUN (clear_log_cmdline
,
451 clear_log_cmdline_cmd
,
452 "clear log cmdline-targets",
455 "Disable log targets specified at startup by --log option\n")
457 zt_file_cmdline
.prio_min
= ZLOG_DISABLED
;
458 zlog_file_set_other(&zt_file_cmdline
);
460 log_cmdline_syslog_lvl
= ZLOG_DISABLED
;
461 zlog_syslog_set_prio_min(ZLOG_MAXLVL(log_config_syslog_lvl
,
462 log_cmdline_syslog_lvl
));
464 log_cmdline_stdout_lvl
= ZLOG_DISABLED
;
465 log_stdout_apply_level();
470 DEFPY (config_log_file
,
472 "log file FILENAME [<emergencies|alerts|critical|errors|warnings|notifications|informational|debugging>$levelarg]",
478 int level
= log_default_lvl
;
481 level
= log_level_match(levelarg
);
482 if (level
== ZLOG_DISABLED
)
483 return CMD_ERR_NO_MATCH
;
485 return set_log_file(&zt_file
, vty
, filename
, level
);
488 DEFUN (no_config_log_file
,
489 no_config_log_file_cmd
,
490 "no log file [FILENAME [LEVEL]]",
493 "Cancel logging to file\n"
494 "Logging file name\n"
497 zt_file
.prio_min
= ZLOG_DISABLED
;
498 zlog_file_set_other(&zt_file
);
502 DEFPY (config_log_syslog
,
503 config_log_syslog_cmd
,
504 "log syslog [<emergencies|alerts|critical|errors|warnings|notifications|informational|debugging>$levelarg]",
506 "Set syslog logging level\n"
512 level
= log_level_match(levelarg
);
514 if (level
== ZLOG_DISABLED
)
515 return CMD_ERR_NO_MATCH
;
517 level
= log_default_lvl
;
519 log_config_syslog_lvl
= level
;
520 zlog_syslog_set_prio_min(ZLOG_MAXLVL(log_config_syslog_lvl
,
521 log_cmdline_syslog_lvl
));
525 DEFUN (no_config_log_syslog
,
526 no_config_log_syslog_cmd
,
527 "no log syslog [<kern|user|mail|daemon|auth|syslog|lpr|news|uucp|cron|local0|local1|local2|local3|local4|local5|local6|local7>] [<emergencies|alerts|critical|errors|warnings|notifications|informational|debugging>]",
530 "Cancel logging to syslog\n"
534 log_config_syslog_lvl
= ZLOG_DISABLED
;
535 zlog_syslog_set_prio_min(ZLOG_MAXLVL(log_config_syslog_lvl
,
536 log_cmdline_syslog_lvl
));
540 DEFPY (config_log_facility
,
541 config_log_facility_cmd
,
542 "log facility <kern|user|mail|daemon|auth|syslog|lpr|news|uucp|cron|local0|local1|local2|local3|local4|local5|local6|local7>$facilityarg",
544 "Facility parameter for syslog messages\n"
547 int facility
= facility_match(facilityarg
);
549 zlog_syslog_set_facility(facility
);
553 DEFUN (no_config_log_facility
,
554 no_config_log_facility_cmd
,
555 "no log facility [<kern|user|mail|daemon|auth|syslog|lpr|news|uucp|cron|local0|local1|local2|local3|local4|local5|local6|local7>]",
558 "Reset syslog facility to default (daemon)\n"
561 zlog_syslog_set_facility(LOG_DAEMON
);
565 DEFUN (config_log_record_priority
,
566 config_log_record_priority_cmd
,
567 "log record-priority",
569 "Log the priority of the message within the message\n")
571 zt_file
.record_priority
= true;
572 zlog_file_set_other(&zt_file
);
573 if (!stdout_journald_in_use
) {
574 zt_stdout_file
.record_priority
= true;
575 zlog_file_set_other(&zt_stdout_file
);
577 zt_filterfile
.parent
.record_priority
= true;
578 zlog_file_set_other(&zt_filterfile
.parent
);
582 DEFUN (no_config_log_record_priority
,
583 no_config_log_record_priority_cmd
,
584 "no log record-priority",
587 "Do not log the priority of the message within the message\n")
589 zt_file
.record_priority
= false;
590 zlog_file_set_other(&zt_file
);
591 if (!stdout_journald_in_use
) {
592 zt_stdout_file
.record_priority
= false;
593 zlog_file_set_other(&zt_stdout_file
);
595 zt_filterfile
.parent
.record_priority
= false;
596 zlog_file_set_other(&zt_filterfile
.parent
);
600 DEFPY (config_log_timestamp_precision
,
601 config_log_timestamp_precision_cmd
,
602 "log timestamp precision (0-6)",
604 "Timestamp configuration\n"
605 "Set the timestamp precision\n"
606 "Number of subsecond digits\n")
608 zt_file
.ts_subsec
= precision
;
609 zlog_file_set_other(&zt_file
);
610 if (!stdout_journald_in_use
) {
611 zt_stdout_file
.ts_subsec
= precision
;
612 zlog_file_set_other(&zt_stdout_file
);
614 zt_filterfile
.parent
.ts_subsec
= precision
;
615 zlog_file_set_other(&zt_filterfile
.parent
);
619 DEFUN (no_config_log_timestamp_precision
,
620 no_config_log_timestamp_precision_cmd
,
621 "no log timestamp precision [(0-6)]",
624 "Timestamp configuration\n"
625 "Reset the timestamp precision to the default value of 0\n"
626 "Number of subsecond digits\n")
628 zt_file
.ts_subsec
= 0;
629 zlog_file_set_other(&zt_file
);
630 if (!stdout_journald_in_use
) {
631 zt_stdout_file
.ts_subsec
= 0;
632 zlog_file_set_other(&zt_stdout_file
);
634 zt_filterfile
.parent
.ts_subsec
= 0;
635 zlog_file_set_other(&zt_filterfile
.parent
);
639 DEFPY (config_log_ec
,
641 "[no] log error-category",
644 "Prefix log message text with [EC 9999] code\n")
646 zlog_set_prefix_ec(!no
);
650 DEFPY (config_log_xid
,
652 "[no] log unique-id",
655 "Prefix log message text with [XXXXX-XXXXX] identifier\n")
657 zlog_set_prefix_xid(!no
);
661 DEFPY (config_log_filterfile
,
662 config_log_filterfile_cmd
,
663 "log filtered-file FILENAME [<emergencies|alerts|critical|errors|warnings|notifications|informational|debugging>$levelarg]",
665 "Logging to file with string filter\n"
669 int level
= log_default_lvl
;
672 level
= log_level_match(levelarg
);
673 if (level
== ZLOG_DISABLED
)
674 return CMD_ERR_NO_MATCH
;
676 return set_log_file(&zt_filterfile
.parent
, vty
, filename
, level
);
679 DEFUN (no_config_log_filterfile
,
680 no_config_log_filterfile_cmd
,
681 "no log filtered-file [FILENAME [LEVEL]]",
684 "Cancel logging to file with string filter\n"
685 "Logging file name\n"
688 zt_filterfile
.parent
.prio_min
= ZLOG_DISABLED
;
689 zlog_file_set_other(&zt_filterfile
.parent
);
695 "[no] log filter-text WORD$filter",
699 "String to filter by\n")
704 ret
= zlog_filter_del(filter
);
706 ret
= zlog_filter_add(filter
);
709 vty_out(vty
, "%% filter table full\n");
711 } else if (ret
!= 0) {
712 vty_out(vty
, "%% failed to %s log filter\n",
713 (no
? "remove" : "apply"));
717 vty_out(vty
, " %s\n", filter
);
721 /* Clear all log filters */
722 DEFPY (log_filter_clear
,
723 log_filter_clear_cmd
,
724 "clear log filter-text",
733 /* Show log filter */
734 DEFPY (show_log_filter
,
736 "show logging filter-text",
738 "Show current logging configuration\n"
741 char log_filters
[ZLOG_FILTERS_MAX
* (ZLOG_FILTER_LENGTH_MAX
+ 3)] = "";
744 len
= zlog_filter_dump(log_filters
, sizeof(log_filters
));
747 vty_out(vty
, "%% failed to get filters\n");
752 vty_out(vty
, "%s", log_filters
);
757 /* Enable/disable 'immediate' mode, with no output buffering */
758 DEFPY (log_immediate_mode
,
759 log_immediate_mode_cmd
,
760 "[no] log immediate-mode",
763 "Output immediately, without buffering\n")
765 zlog_set_immediate(!no
);
769 void log_config_write(struct vty
*vty
)
771 bool show_cmdline_hint
= false;
773 if (zt_file
.prio_min
!= ZLOG_DISABLED
&& zt_file
.filename
) {
774 vty_out(vty
, "log file %s", zt_file
.filename
);
776 if (zt_file
.prio_min
!= log_default_lvl
)
777 vty_out(vty
, " %s", zlog_priority
[zt_file
.prio_min
]);
781 if (zt_filterfile
.parent
.prio_min
!= ZLOG_DISABLED
782 && zt_filterfile
.parent
.filename
) {
783 vty_out(vty
, "log filtered-file %s",
784 zt_filterfile
.parent
.filename
);
786 if (zt_filterfile
.parent
.prio_min
!= log_default_lvl
)
788 zlog_priority
[zt_filterfile
.parent
.prio_min
]);
792 if (log_config_stdout_lvl
!= ZLOG_DISABLED
) {
793 vty_out(vty
, "log stdout");
795 if (log_config_stdout_lvl
!= log_default_lvl
)
797 zlog_priority
[log_config_stdout_lvl
]);
801 if (log_config_syslog_lvl
!= ZLOG_DISABLED
) {
802 vty_out(vty
, "log syslog");
804 if (log_config_syslog_lvl
!= log_default_lvl
)
806 zlog_priority
[log_config_syslog_lvl
]);
810 if (log_cmdline_syslog_lvl
!= ZLOG_DISABLED
) {
812 "! \"log syslog %s\" enabled by \"--log\" startup option\n",
813 zlog_priority
[log_cmdline_syslog_lvl
]);
814 show_cmdline_hint
= true;
816 if (log_cmdline_stdout_lvl
!= ZLOG_DISABLED
) {
818 "! \"log stdout %s\" enabled by \"--log\" startup option\n",
819 zlog_priority
[log_cmdline_stdout_lvl
]);
820 show_cmdline_hint
= true;
822 if (zt_file_cmdline
.prio_min
!= ZLOG_DISABLED
) {
824 "! \"log file %s %s\" enabled by \"--log\" startup option\n",
825 zt_file_cmdline
.filename
,
826 zlog_priority
[zt_file_cmdline
.prio_min
]);
827 show_cmdline_hint
= true;
829 if (show_cmdline_hint
)
831 "! use \"clear log cmdline-targets\" to remove this target\n");
833 if (zlog_syslog_get_facility() != LOG_DAEMON
)
834 vty_out(vty
, "log facility %s\n",
835 facility_name(zlog_syslog_get_facility()));
837 if (zt_file
.record_priority
== 1)
838 vty_out(vty
, "log record-priority\n");
840 if (zt_file
.ts_subsec
> 0)
841 vty_out(vty
, "log timestamp precision %d\n",
844 if (!zlog_get_prefix_ec())
845 vty_out(vty
, "no log error-category\n");
846 if (!zlog_get_prefix_xid())
847 vty_out(vty
, "no log unique-id\n");
849 if (logmsgs_with_persist_bt
) {
850 struct xrefdata
*xrd
;
851 struct xrefdata_logmsg
*xrdl
;
855 frr_each (xrefdata_uid
, &xrefdata_uid
, xrd
) {
856 if (xrd
->xref
->type
!= XREFT_LOGMSG
)
859 xrdl
= container_of(xrd
, struct xrefdata_logmsg
,
861 if (xrdl
->fl_print_bt
& LOGMSG_FLAG_PERSISTENT
)
862 vty_out(vty
, "debug unique-id %s backtrace\n",
868 static int log_vty_init(const char *progname
, const char *protoname
,
869 unsigned short instance
, uid_t uid
, gid_t gid
)
871 zlog_progname
= progname
;
872 zlog_protoname
= protoname
;
874 zlog_set_prefix_ec(true);
875 zlog_set_prefix_xid(true);
877 zlog_filterfile_init(&zt_filterfile
);
879 if (sd_stdout_is_journal
) {
880 stdout_journald_in_use
= true;
881 zlog_5424_init(&zt_stdout_journald
);
882 zlog_5424_apply_dst(&zt_stdout_journald
);
884 zlog_file_set_fd(&zt_stdout_file
, STDOUT_FILENO
);
888 __attribute__((_CONSTRUCTOR(475))) static void log_vty_preinit(void)
890 hook_register(zlog_init
, log_vty_init
);
893 void log_cmd_init(void)
895 install_element(VIEW_NODE
, &show_logging_cmd
);
896 install_element(ENABLE_NODE
, &clear_log_cmdline_cmd
);
898 install_element(CONFIG_NODE
, &config_log_stdout_cmd
);
899 install_element(CONFIG_NODE
, &no_config_log_stdout_cmd
);
900 install_element(CONFIG_NODE
, &config_log_monitor_cmd
);
901 install_element(CONFIG_NODE
, &no_config_log_monitor_cmd
);
902 install_element(CONFIG_NODE
, &config_log_file_cmd
);
903 install_element(CONFIG_NODE
, &no_config_log_file_cmd
);
904 install_element(CONFIG_NODE
, &config_log_syslog_cmd
);
905 install_element(CONFIG_NODE
, &no_config_log_syslog_cmd
);
906 install_element(CONFIG_NODE
, &config_log_facility_cmd
);
907 install_element(CONFIG_NODE
, &no_config_log_facility_cmd
);
908 install_element(CONFIG_NODE
, &config_log_record_priority_cmd
);
909 install_element(CONFIG_NODE
, &no_config_log_record_priority_cmd
);
910 install_element(CONFIG_NODE
, &config_log_timestamp_precision_cmd
);
911 install_element(CONFIG_NODE
, &no_config_log_timestamp_precision_cmd
);
912 install_element(CONFIG_NODE
, &config_log_ec_cmd
);
913 install_element(CONFIG_NODE
, &config_log_xid_cmd
);
915 install_element(VIEW_NODE
, &show_log_filter_cmd
);
916 install_element(CONFIG_NODE
, &log_filter_cmd
);
917 install_element(CONFIG_NODE
, &log_filter_clear_cmd
);
918 install_element(CONFIG_NODE
, &config_log_filterfile_cmd
);
919 install_element(CONFIG_NODE
, &no_config_log_filterfile_cmd
);
920 install_element(CONFIG_NODE
, &log_immediate_mode_cmd
);
922 install_element(ENABLE_NODE
, &debug_uid_backtrace_cmd
);
923 install_element(CONFIG_NODE
, &debug_uid_backtrace_cmd
);