From 800502239138b03574dca2469106eb82b7817902 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Thu, 17 Nov 2011 15:56:11 -0500 Subject: [PATCH] Add adjustable logging verbosity to slow_bend.py. --- posts/slow_bend/slow_bend.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/posts/slow_bend/slow_bend.py b/posts/slow_bend/slow_bend.py index 19b314d..e7231f0 100755 --- a/posts/slow_bend/slow_bend.py +++ b/posts/slow_bend/slow_bend.py @@ -209,11 +209,11 @@ def _get_data_stream(data_dir=None, logger=None): _time.sleep(1) # try the next second return open(data_path, 'w') -def _get_logger(log_level=_logging.DEBUG): +def _get_logger(level=_logging.DEBUG): logger = _logging.getLogger('slow_bend') - logger.setLevel(log_level) + logger.setLevel(level) ch = _logging.StreamHandler() - ch.setLevel(log_level) + ch.setLevel(level) formatter = _logging.Formatter( '%(asctime)s - %(name)s - %(levelname)s - %(message)s') ch.setFormatter(formatter) @@ -242,13 +242,17 @@ if __name__ == '__main__': help='Also record the temperature') parser.add_argument( '-v', '--verbose', dest='verbose', - default=False, action='store_const', const=True, - help='Print lots of debugging information') + default=0, action='count', + help='Print debugging information (repeat to increase verbosity)') args = parser.parse_args() if args.verbose: - logger = _get_logger() + if args.verbose > 1: + level = _logging.DEBUG + else: + level = _logging.INFO + logger = _get_logger(level=level) else: logger = None -- 2.26.2