X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fvlib%2Flog.c;h=d084511a647f5aaa707f0134ed12dbd8d9f1d263;hb=972dc17634e430cb93b97c67b50096acc3164231;hp=e1ab036b25c75e42678b19dbe99debf5d49da781;hpb=4d7ad4a6cc08e316d78de5ac7ce3ead4e9bfcb66;p=vpp.git diff --git a/src/vlib/log.c b/src/vlib/log.c index e1ab036b25c..d084511a647 100644 --- a/src/vlib/log.c +++ b/src/vlib/log.c @@ -18,12 +18,14 @@ #include #include #include +#include vlib_log_main_t log_main = { .default_log_level = VLIB_LOG_LEVEL_NOTICE, .default_syslog_log_level = VLIB_LOG_LEVEL_WARNING, .unthrottle_time = 3, .size = 512, + .add_to_elog = 1, .default_rate_limit = 50, }; @@ -222,6 +224,37 @@ vlib_log (vlib_log_level_t level, vlib_log_class_t class, char *fmt, ...) e->timestamp = t; s = 0; + if (lm->add_to_elog) + { + /* *INDENT-OFF* */ + ELOG_TYPE_DECLARE(ee) = + { + .format = "log-%s: %s", + .format_args = "t4T4", + .n_enum_strings = 9, + .enum_strings = { + "emerg", + "alert", + "crit", + "err", + "warn", + "notice", + "info", + "debug", + "disabled", + }, + }; + struct { + u32 log_level; + u32 string_index; + } *ed; + /* *INDENT-ON* */ + ed = ELOG_DATA (&vlib_global_main.elog_main, ee); + ed->log_level = level; + ed->string_index = + elog_string (&vlib_global_main.elog_main, "%v%c", e->string, 0); + } + lm->next = (lm->next + 1) % lm->size; if (lm->size > lm->count) lm->count++; @@ -333,8 +366,8 @@ format_vlib_log_level (u8 * s, va_list * args) return format (s, "%s", t); } -static clib_error_t * -vlib_log_init (vlib_main_t * vm) +clib_error_t * +vlib_log_init (vlib_main_t *vm) { vlib_log_main_t *lm = &log_main; vlib_log_class_registration_t *r = lm->registrations; @@ -363,9 +396,6 @@ vlib_log_init (vlib_main_t * vm) return 0; } -VLIB_INIT_FUNCTION (vlib_log_init); - - static clib_error_t * show_log (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd) @@ -383,10 +413,9 @@ show_log (vlib_main_t * vm, while (count--) { e = vec_elt_at_index (lm->entries, i); - vlib_cli_output (vm, "%U %-10U %-14U %v", - format_time_float, 0, e->timestamp + time_offset, - format_vlib_log_level, e->level, - format_vlib_log_class, e->class, e->string); + vlib_cli_output (vm, "%U %-10U %-14U %v", format_time_float, NULL, + e->timestamp + time_offset, format_vlib_log_level, + e->level, format_vlib_log_class, e->class, e->string); i = (i + 1) % lm->size; } @@ -822,6 +851,8 @@ log_config (vlib_main_t * vm, unformat_input_t * input) unformat_vlib_log_level, &lm->default_syslog_log_level)) ; + else if (unformat (input, "add-to-elog")) + lm->add_to_elog = 1; else if (unformat (input, "class %s %U", &class, unformat_vlib_cli_sub_input, &sub_input)) {