From: Zach Welch zach@mandolincreekfarm.com
# HG changeset patch # User Zach Welch zach@mandolincreekfarm.com # Fake Node ID f9766c707308a213b993ea42f01872100a054c87
Expose console verbosity (#2347)
This patch adds a method to query the console verbosity level. This is useful for code that needs to produce non-logging output, conditional on whether the --quiet or --verbose options were given.
diff --git a/chirp/logger.py b/chirp/logger.py index eb29e6f..6e841bc 100644 --- a/chirp/logger.py +++ b/chirp/logger.py @@ -97,6 +97,7 @@ class Logger(object): self.early_level = logging.DEBUG
self.console = logging.StreamHandler(console_stream) + self.console_level = self.early_level self.console.setLevel(self.early_level) self.console.setFormatter(logging.Formatter(console_format)) self.logger.addHandler(self.console) @@ -132,6 +133,7 @@ class Logger(object): self.LOG.debug("verbosity=%d", level) if level > logging.CRITICAL: level = logging.CRITICAL + self.console_level = level self.console.setLevel(level)
def set_log_level(self, level): @@ -148,6 +150,11 @@ class Logger(object): Logger.instance = Logger()
+def is_visible(level): + """Returns True if a message at level will be shown on the console""" + return level >= Logger.instance.console_level + + def add_arguments(parser): parser.add_argument("-q", "--quiet", action="count", default=0, help="Decrease verbosity")