diff options
author | Damjan Marion <damarion@cisco.com> | 2020-10-21 19:43:36 +0200 |
---|---|---|
committer | Florin Coras <florin.coras@gmail.com> | 2020-10-21 21:52:17 +0000 |
commit | 055e64066d88576ed516e5f50de7ec3d5b6cef0a (patch) | |
tree | f958b11ba38e4735b5fd858b927eece527e9aa1d | |
parent | 65c56c83ce4e58178b5ad90a8f325692c9904381 (diff) |
vlib: per-class logging configuration in startup.conf
logging {
class avf {
rate-limit 200
level debug
syslog-level debug
}
class dpdk/cryptodev {
rate-limit 200
level disabled
syslog-level disabled
}
}
Type: improvement
Change-Id: Iebe49b3ed4dfbfd589e80fcd2f9a63a8fe66b83b
Signed-off-by: Damjan Marion <damarion@cisco.com>
-rw-r--r-- | src/vlib/log.c | 89 | ||||
-rw-r--r-- | src/vlib/log.h | 11 | ||||
-rw-r--r-- | src/vpp/conf/startup.conf | 2 |
3 files changed, 99 insertions, 3 deletions
diff --git a/src/vlib/log.c b/src/vlib/log.c index a4514206bae..27d2e16b006 100644 --- a/src/vlib/log.c +++ b/src/vlib/log.c @@ -234,8 +234,19 @@ vlib_log_register_class_internal (char *class, char *subclass, u32 limit) vlib_log_class_data_t *c = NULL; vlib_log_subclass_data_t *s; vlib_log_class_data_t *tmp; + vlib_log_class_config_t *cc = 0, *scc = 0; + uword *p; + u8 *str; u32 length = 0; + if ((p = hash_get_mem (lm->config_index_by_name, class))) + cc = vec_elt_at_index (lm->configs, p[0]); + + str = format (0, "%s/%s%c", class, subclass, 0); + if ((p = hash_get_mem (lm->config_index_by_name, (char *) str))) + scc = vec_elt_at_index (lm->configs, p[0]); + vec_free (str); + vec_foreach (tmp, lm->classes) { if (vec_len (tmp->name) != strlen (class)) @@ -257,9 +268,30 @@ vlib_log_register_class_internal (char *class, char *subclass, u32 limit) vec_add2 (c->subclasses, s, 1); s->index = s - c->subclasses; s->name = subclass ? format (0, "%s", subclass) : 0; - s->rate_limit = (limit == 0) ? lm->default_rate_limit : limit; - s->level = lm->default_log_level; - s->syslog_level = lm->default_syslog_log_level; + + if (scc && scc->rate_limit != ~0) + s->rate_limit = scc->rate_limit; + else if (cc && cc->rate_limit != ~0) + s->rate_limit = cc->rate_limit; + else if (limit) + s->rate_limit = limit; + else + s->rate_limit = lm->default_rate_limit; + + if (scc && scc->level != ~0) + s->level = scc->level; + else if (cc && cc->level != ~0) + s->level = cc->level; + else + s->level = lm->default_log_level; + + if (scc && scc->syslog_level != ~0) + s->syslog_level = scc->syslog_level; + else if (cc && cc->syslog_level != ~0) + s->syslog_level = cc->syslog_level; + else + s->syslog_level = lm->default_syslog_log_level; + if (subclass) length += 1 + vec_len (s->name); if (length > lm->max_class_name_length) @@ -712,9 +744,50 @@ VLIB_CLI_COMMAND (cli_test_log, static) = { /* *INDENT-ON* */ static clib_error_t * +log_config_class (vlib_main_t * vm, char *name, unformat_input_t * input) +{ + vlib_log_main_t *lm = &log_main; + vlib_log_class_config_t *cc, tmp; + uword *p; + + if (lm->config_index_by_name == 0) + lm->config_index_by_name = hash_create_string (0, sizeof (uword)); + + p = hash_get_mem (lm->config_index_by_name, name); + + if (p) + return clib_error_return (0, "logging class '%s' already configured", + name); + + clib_memset_u8 (&tmp, 0xff, sizeof (vlib_log_class_config_t)); + + while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (input, "level %U", unformat_vlib_log_level, &tmp.level)) + ; + else if (unformat (input, "syslog-level %U", unformat_vlib_log_level, + &tmp.syslog_level)) + ; + else if (unformat (input, "rate-limit %u", &tmp.rate_limit)) + ; + else + return clib_error_return (0, "unknown input '%U'", + format_unformat_error, input); + } + + vec_add2 (lm->configs, cc, 1); + clib_memcpy_fast (cc, &tmp, sizeof (vlib_log_class_config_t)); + cc->name = name; + hash_set_mem (lm->config_index_by_name, name, cc - lm->configs); + return 0; +} + +static clib_error_t * log_config (vlib_main_t * vm, unformat_input_t * input) { vlib_log_main_t *lm = &log_main; + unformat_input_t sub_input; + u8 *class = 0; while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) { @@ -729,6 +802,16 @@ log_config (vlib_main_t * vm, unformat_input_t * input) unformat_vlib_log_level, &lm->default_syslog_log_level)) ; + else if (unformat (input, "class %s %U", &class, + unformat_vlib_cli_sub_input, &sub_input)) + { + clib_error_t *err; + err = log_config_class (vm, (char *) class, &sub_input); + class = 0; + unformat_free (&sub_input); + if (err) + return err; + } else { return unformat_parse_error (input); diff --git a/src/vlib/log.h b/src/vlib/log.h index 9a0c44475d2..4cceb4b962a 100644 --- a/src/vlib/log.h +++ b/src/vlib/log.h @@ -68,6 +68,14 @@ typedef struct typedef struct { + vlib_log_level_t level; + vlib_log_level_t syslog_level; + int rate_limit; + char *name; +} vlib_log_class_config_t; + +typedef struct +{ vlib_log_entry_t *entries; vlib_log_class_data_t *classes; int size, next, count; @@ -85,6 +93,9 @@ typedef struct struct timeval time_zero_timeval; f64 time_zero; + /* config */ + vlib_log_class_config_t *configs; + uword *config_index_by_name; } vlib_log_main_t; extern vlib_log_main_t log_main; diff --git a/src/vpp/conf/startup.conf b/src/vpp/conf/startup.conf index 8b02ac89085..864de11251f 100644 --- a/src/vpp/conf/startup.conf +++ b/src/vpp/conf/startup.conf @@ -239,4 +239,6 @@ cpu { # default-log-level debug ## set default logging level for syslog or stderr output # default-syslog-log-level info + ## Set per-class configuration + # class dpdk/cryptodev { rate-limit 100 level debug syslog-level error } # } |