Introduce a new trace-cmd internal function to set the application log level. trace_set_verbose() The log level can be set using string with log id or log name. Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@xxxxxxxxx> --- tracecmd/include/trace-local.h | 2 ++ tracecmd/trace-cmd.c | 41 ++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/tracecmd/include/trace-local.h b/tracecmd/include/trace-local.h index 1218de12..cb929be4 100644 --- a/tracecmd/include/trace-local.h +++ b/tracecmd/include/trace-local.h @@ -36,6 +36,8 @@ void usage(char **argv); extern int silence_warnings; extern int show_status; +int trace_set_verbose(char *level); + struct pid_record_data { int pid; int brass[2]; diff --git a/tracecmd/trace-cmd.c b/tracecmd/trace-cmd.c index 60cd3ea1..4e4a73af 100644 --- a/tracecmd/trace-cmd.c +++ b/tracecmd/trace-cmd.c @@ -45,6 +45,47 @@ void *malloc_or_die(unsigned int size) return data; } +static struct trace_log_severity { + int id; + const char *name; +} log_severtity[] = { + { .id = TEP_LOG_NONE, .name = "none" }, + { .id = TEP_LOG_CRITICAL, .name = "crit" }, + { .id = TEP_LOG_ERROR, .name = "err" }, + { .id = TEP_LOG_WARNING, .name = "warn" }, + { .id = TEP_LOG_INFO, .name = "info" }, + { .id = TEP_LOG_DEBUG, .name = "debug" }, + { .id = TEP_LOG_ALL, .name = "all" }, +}; + +int trace_set_verbose(char *level) +{ + int id; + + if (!level) + return -1; + + if (isdigit(level[0])) { + id = atoi(level); + if (id >= TEP_LOG_NONE && id <= TEP_LOG_ALL) { + tracecmd_set_loglevel(id); + return 0; + } + } else { + int size = sizeof(log_severtity) / sizeof(log_severtity[0]); + int i; + + for (i = 0; i < size; i++) { + if (strlen(level) >= strlen(log_severtity[i].name) && + !strncmp(level, log_severtity[i].name, strlen(log_severtity[i].name))) { + tracecmd_set_loglevel(log_severtity[i].id); + return 0; + } + } + } + + return -1; +} /** * struct command -- 2.30.2