From 67964cbcdae38cb2adfe07613eb2de4077d146eb Mon Sep 17 00:00:00 2001 From: David Sterba Date: Wed, 22 Feb 2023 01:00:12 +0100 Subject: [PATCH] btrfs-progs: add global option --log=level Add an option to set the log level exactly instead of -vv and similar. The combined option may not be known to all users as reported and one option for the level is for convenience. Issue: #570 Signed-off-by: David Sterba --- btrfs.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/btrfs.c b/btrfs.c index f95425e7..6a72ffa6 100644 --- a/btrfs.c +++ b/btrfs.c @@ -32,7 +32,7 @@ #include "cmds/commands.h" static const char * const btrfs_cmd_group_usage[] = { - "btrfs [--help] [--version] [--format ] [-v|--verbose] [-q|--quiet] [...] []", + "btrfs [--help] [--version] [--format ] [-v|--verbose] [-q|--quiet] [--log=level] [...] []", NULL }; @@ -238,6 +238,23 @@ static void handle_output_format(const char *format) } } +static void handle_log_level(const char *level) { + if (strcasecmp(level, "default") == 0) { + bconf.verbose = LOG_DEFAULT; + } else if (strcasecmp(level, "info") == 0) { + bconf.verbose = LOG_INFO; + } else if (strcasecmp(level, "verbose") == 0) { + bconf.verbose = LOG_VERBOSE; + } else if (strcasecmp(level, "debug") == 0) { + bconf.verbose = LOG_DEBUG; + } else if (strcasecmp(level, "quiet") == 0) { + bconf.verbose = BTRFS_BCONF_QUIET; + } else { + error("unrecognized log level: %s", level); + exit(1); + } +} + /* * Parse global options, between binary name and first non-option argument * after processing all valid options (including those with arguments). @@ -246,7 +263,7 @@ static void handle_output_format(const char *format) */ static int handle_global_options(int argc, char **argv) { - enum { OPT_HELP = 256, OPT_VERSION, OPT_FULL, OPT_FORMAT }; + enum { OPT_HELP = 256, OPT_VERSION, OPT_FULL, OPT_FORMAT, OPT_LOG }; static const struct option long_options[] = { { "help", no_argument, NULL, OPT_HELP }, { "version", no_argument, NULL, OPT_VERSION }, @@ -254,6 +271,7 @@ static int handle_global_options(int argc, char **argv) { "full", no_argument, NULL, OPT_FULL }, { "verbose", no_argument, NULL, 'v' }, { "quiet", no_argument, NULL, 'q' }, + { "log", required_argument, NULL, OPT_LOG }, { NULL, 0, NULL, 0} }; int shift; @@ -276,6 +294,9 @@ static int handle_global_options(int argc, char **argv) case OPT_FORMAT: handle_output_format(optarg); break; + case OPT_LOG: + handle_log_level(optarg); + break; case 'v': bconf_be_verbose(); break;