Add adjustable logging verbosity to slow_bend.py.
authorW. Trevor King <wking@drexel.edu>
Thu, 17 Nov 2011 20:56:11 +0000 (15:56 -0500)
committerW. Trevor King <wking@drexel.edu>
Thu, 17 Nov 2011 20:56:11 +0000 (15:56 -0500)
posts/slow_bend/slow_bend.py

index 19b314dfb20ddc6a2744c687d5ab793659b2efbc..e7231f0d747518ecbda3f3c75dd0d48b16bfc078 100755 (executable)
@@ -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