X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fvlib%2Flog.c;h=9a0d75fe3ac8e3cd242d3a1b6e5754e6d9fa9bf8;hb=593eedf2561f639703d366cd21ab0c3ae03bdb0c;hp=8e205b9b74aca67238004f6b0463af7e137557c1;hpb=ffb3813dd352a8b12fddfa2730dde390f1b92104;p=vpp.git diff --git a/src/vlib/log.c b/src/vlib/log.c index 8e205b9b74a..9a0d75fe3ac 100644 --- a/src/vlib/log.c +++ b/src/vlib/log.c @@ -62,6 +62,11 @@ typedef struct int default_syslog_log_level; int unthrottle_time; u32 indent; + + /* time zero */ + struct timeval time_zero_timeval; + f64 time_zero; + } vlib_log_main_t; vlib_log_main_t log_main = { @@ -227,6 +232,8 @@ vlib_log_register_class (char *class, char *subclass) vlib_log_class_data_t *tmp; vec_foreach (tmp, lm->classes) { + if (vec_len (tmp->name) != strlen (class)) + continue; if (!memcmp (class, tmp->name, vec_len (tmp->name))) { c = tmp; @@ -276,6 +283,10 @@ static clib_error_t * vlib_log_init (vlib_main_t * vm) { vlib_log_main_t *lm = &log_main; + + gettimeofday (&lm->time_zero_timeval, 0); + lm->time_zero = vlib_time_now (vm); + vec_validate (lm->entries, lm->size); lm->log_class = vlib_log_register_class ("log", 0); u8 *tmp = format (NULL, "%U %-10U %-10U ", format_time_float, 0, (f64) 0, @@ -297,12 +308,16 @@ show_log (vlib_main_t * vm, vlib_log_entry_t *e; int i = last_log_entry (); int count = lm->count; + f64 time_offset; + + time_offset = (f64) lm->time_zero_timeval.tv_sec + + (((f64) lm->time_zero_timeval.tv_usec) * 1e-6) - lm->time_zero; while (count--) { e = vec_elt_at_index (lm->entries, i); vlib_cli_output (vm, "%U %-10U %-10U %v", - format_time_float, 0, e->timestamp, + format_time_float, 0, e->timestamp + time_offset, format_vlib_log_level, e->level, format_vlib_log_class, e->class, e->string); i = (i + 1) % lm->size; @@ -340,18 +355,21 @@ show_log_config (vlib_main_t * vm, vlib_cli_output (vm, "%-22s %-14s %-14s %s", "Class/Subclass", "Level", "Syslog Level", "Rate Limit"); + + u8 *defstr = format (0, "default"); vec_foreach (c, lm->classes) { - vlib_cli_output (vm, "%s", c->name); + vlib_cli_output (vm, "%v", c->name); vec_foreach (sc, c->subclasses) { - vlib_cli_output (vm, " %-20s %-14U %-14U %d", - sc->name ? (char *) sc->name : "default", + vlib_cli_output (vm, " %-20v %-14U %-14U %d", + sc->name ? sc->name : defstr, format_vlib_log_level, sc->level, format_vlib_log_level, sc->syslog_level, sc->rate_limit); } } + vec_free (defstr); return error; } @@ -673,7 +691,7 @@ test_log_class_subclass (vlib_main_t * vm, /* *INDENT-OFF* */ VLIB_CLI_COMMAND (cli_test_log, static) = { .path = "test log", - .short_help = "test log