aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2010-05-11 16:39:22 +0200
committerHarald Welte <laforge@gnumonks.org>2010-05-11 16:39:22 +0200
commit7638af95fd08213aef4adb3c6399975fe3621855 (patch)
tree3436379d7cda6e3f79be6c85891da15d55a23f4c
parent9ac2225ff43e7ec74ec6a629383899f3b6e78d2c (diff)
logging: add log_vty_{level,category}_string()0.1.6
-rw-r--r--include/osmocore/logging.h4
-rw-r--r--src/logging.c46
2 files changed, 50 insertions, 0 deletions
diff --git a/include/osmocore/logging.h b/include/osmocore/logging.h
index b9e0c8f..2e82959 100644
--- a/include/osmocore/logging.h
+++ b/include/osmocore/logging.h
@@ -128,4 +128,8 @@ struct log_target *log_target_create_stderr(void);
void log_add_target(struct log_target *target);
void log_del_target(struct log_target *target);
+/* Gernerate command argument strings for VTY use */
+const char *log_vty_category_string(struct log_info *info);
+const char *log_vty_level_string(struct log_info *info);
+
#endif /* _OSMOCORE_LOGGING_H */
diff --git a/src/logging.c b/src/logging.c
index e5d459a..e72a6e2 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");