diff options
author | Sean Anderson <seanga2@gmail.com> | 2020-10-27 19:55:33 -0400 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2020-10-30 10:55:27 -0400 |
commit | fed9c2fbc941660f3a6ea25013f6501d4cff8f86 (patch) | |
tree | e109d3bd8db7185aa64e711717deb655e3e47608 /cmd/log.c | |
parent | f48b5b563488c1fb8d2bb4857df8fa06a7a00a52 (diff) | |
download | u-boot-fed9c2fbc941660f3a6ea25013f6501d4cff8f86.tar.gz u-boot-fed9c2fbc941660f3a6ea25013f6501d4cff8f86.tar.bz2 u-boot-fed9c2fbc941660f3a6ea25013f6501d4cff8f86.zip |
cmd: log: Split off log level parsing
Move parsing of log level into its own function so it can be re-used. This
also adds support for using log level names instead of just the integer
equivalent.
Signed-off-by: Sean Anderson <seanga2@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'cmd/log.c')
-rw-r--r-- | cmd/log.c | 29 |
1 files changed, 23 insertions, 6 deletions
@@ -11,23 +11,40 @@ static char log_fmt_chars[LOGF_COUNT] = "clFLfm"; +static enum log_level_t parse_log_level(char *const arg) +{ + enum log_level_t ret; + ulong level; + + if (!strict_strtoul(arg, 10, &level)) { + if (level > _LOG_MAX_LEVEL) { + printf("Only log levels <= %d are supported\n", + _LOG_MAX_LEVEL); + return LOGL_NONE; + } + return level; + } + + ret = log_get_level_by_name(arg); + if (ret == LOGL_NONE) + printf("Unknown log level \"%s\"\n", arg); + return ret; +} + static int do_log_level(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { if (argc > 1) { - long log_level = simple_strtol(argv[1], NULL, 10); + enum log_level_t log_level = parse_log_level(argv[1]); - if (log_level < 0 || log_level > _LOG_MAX_LEVEL) { - printf("Only log levels <= %d are supported\n", - _LOG_MAX_LEVEL); + if (log_level == LOGL_NONE) return CMD_RET_FAILURE; - } gd->default_log_level = log_level; } else { printf("Default log level: %d\n", gd->default_log_level); } - return 0; + return CMD_RET_SUCCESS; } static int do_log_format(struct cmd_tbl *cmdtp, int flag, int argc, |