diff options
author | Harald Welte <laforge@gnumonks.org> | 2010-05-11 16:39:22 +0200 |
---|---|---|
committer | Harald Welte <laforge@gnumonks.org> | 2010-05-11 16:39:22 +0200 |
commit | 7638af95fd08213aef4adb3c6399975fe3621855 (patch) | |
tree | 3436379d7cda6e3f79be6c85891da15d55a23f4c /src/logging.c | |
parent | 9ac2225ff43e7ec74ec6a629383899f3b6e78d2c (diff) |
logging: add log_vty_{level,category}_string()
Diffstat (limited to 'src/logging.c')
-rw-r--r-- | src/logging.c | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/src/logging.c b/src/logging.c index e5d459a0..e72a6e20 100644 --- a/src/logging.c +++ b/src/logging.c @@ -366,6 +366,52 @@ struct log_target *log_target_create_stderr(void) #endif /* stderr */ } +const char *log_vty_level_string(struct log_info *info) +{ + const struct value_string *vs; + unsigned int len = 3; /* ()\0 */ + char *str; + + for (vs = loglevel_strs; vs->value || vs->str; vs++) + len += strlen(vs->str) + 1; + + str = talloc_zero_size(NULL, len); + if (!str) + return NULL; + + str[0] = '('; + for (vs = loglevel_strs; vs->value || vs->str; vs++) { + strcat(str, vs->str); + strcat(str, "|"); + } + str[strlen(str)-1] = ')'; + + return str; +} + +const char *log_vty_category_string(struct log_info *info) +{ + unsigned int len = 3; /* "()\0" */ + unsigned int i; + char *str; + + for (i = 0; i < info->num_cat; i++) + len += strlen(info->cat[i].name) + 1; + + str = talloc_zero_size(NULL, len); + if (!str) + return NULL; + + str[0] = '('; + for (i = 0; i < info->num_cat; i++) { + strcat(str, info->cat[i].name+1); + strcat(str, "|"); + } + str[strlen(str)-1] = ')'; + + return str; +} + void log_init(const struct log_info *cat) { tall_log_ctx = talloc_named_const(NULL, 1, "logging"); |