From 964a6377e7ddbb3e21ebe7cf6c117a3e3f88df72 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Tue, 4 Oct 2022 20:57:58 +0200 Subject: [PATCH] btrfs-progs: factor out check for message level Factor out the level check so we can add helper for stderr as some commands don't/can't print to stdout. Signed-off-by: David Sterba --- common/messages.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/common/messages.c b/common/messages.c index 63bc8ff8..f2efec31 100644 --- a/common/messages.c +++ b/common/messages.c @@ -102,6 +102,19 @@ void internal_error(const char *fmt, ...) #endif } +static bool should_print(int level) +{ + if (bconf.verbose == BTRFS_BCONF_QUIET || level == BTRFS_BCONF_QUIET) + return false; + + if (bconf.verbose == BTRFS_BCONF_UNSET && level == LOG_DEFAULT) + return true; + if (bconf.verbose < level) + return false; + + return true; +} + /* * Print a message according to the global verbosity level. * @@ -112,12 +125,7 @@ void pr_verbose(int level, const char *fmt, ...) { va_list args; - if (bconf.verbose == BTRFS_BCONF_QUIET || level == BTRFS_BCONF_QUIET) - return; - - if (bconf.verbose == BTRFS_BCONF_UNSET && level == LOG_DEFAULT) - /* Pass */; - else if (bconf.verbose < level) + if (!should_print(level)) return; va_start(args, fmt);