]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-deploy.git/commitdiff
Send log msgs to file '{cluster}.log' as well as console.
authorSage Weil <sage@inktank.com>
Thu, 28 Mar 2013 01:46:22 +0000 (18:46 -0700)
committerSage Weil <sage@inktank.com>
Thu, 28 Mar 2013 01:46:22 +0000 (18:46 -0700)
Default log level is INFO to console, DEBUG to logfile
--verbose changes console log level to DEBUG as well
logfile gets timestamp modulename level msg, console gets just msg

Fixes: #4468
Signed-off-by: Dan Mick <dan.mick@inktank.com>
ceph_deploy/cli.py

index 7ceee8ed38f47f462e1ced4cabb0d8ce1df9afa0..7f286ad3bdbd0af68f5a05e050c444cd159de726 100644 (file)
@@ -81,13 +81,27 @@ def parse_args(args=None, namespace=None):
 def main(args=None, namespace=None):
     args = parse_args(args=args, namespace=namespace)
 
-    loglevel = logging.INFO
+    console_loglevel = logging.INFO
     if args.verbose:
-        loglevel = logging.DEBUG
+        console_loglevel = logging.DEBUG
+    sh = logging.StreamHandler()
+    sh.setLevel(console_loglevel)
 
-    logging.basicConfig(
-        level=loglevel,
-        )
+    fh = logging.FileHandler('{cluster}.log'.format(cluster=args.cluster))
+    fh.setLevel(logging.DEBUG)
+    formatter = logging.Formatter(
+        '%(asctime)s %(name)s %(levelname)s %(message)s')
+    fh.setFormatter(formatter)
+
+    # because we're in a module already, __name__ is not the ancestor of
+    # the rest of the package; use the root as the logger for everyone
+    root_logger = logging.getLogger()
+
+    # allow all levels at root_logger, handlers control individual levels
+    root_logger.setLevel(logging.DEBUG)
+
+    root_logger.addHandler(sh)
+    root_logger.addHandler(fh)
 
     sudo_pushy.patch()