]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
ceph-volume: log: create a utility for setting up logging
authorAlfredo Deza <adeza@redhat.com>
Mon, 19 Jun 2017 20:19:24 +0000 (16:19 -0400)
committerAlfredo Deza <adeza@redhat.com>
Fri, 4 Aug 2017 14:25:57 +0000 (10:25 -0400)
Signed-off-by: Alfredo Deza <adeza@redhat.com>
src/ceph-volume/ceph_volume/log.py [new file with mode: 0644]

diff --git a/src/ceph-volume/ceph_volume/log.py b/src/ceph-volume/ceph_volume/log.py
new file mode 100644 (file)
index 0000000..78e26a1
--- /dev/null
@@ -0,0 +1,24 @@
+from datetime import datetime
+import logging
+import os
+
+BASE_FORMAT = "[%(name)s][%(levelname)-6s] %(message)s"
+FILE_FORMAT = "[%(asctime)s]" + BASE_FORMAT
+
+
+def setup(config=None):
+    root_logger = logging.getLogger()
+    log_path = config.get('--log-path', '/var/log/ceph/')
+    if not os.path.exists(log_path):
+        raise RuntimeError('configured ``--log-path`` value does not exist: %s' % log_path)
+    date = datetime.strftime(datetime.utcnow(), '%Y-%m-%d')
+    log_file = os.path.join(log_path, 'ceph-volume-%s.log' % date)
+
+    root_logger.setLevel(logging.DEBUG)
+
+    # File Logger
+    fh = logging.FileHandler(log_file)
+    fh.setLevel(logging.DEBUG)
+    fh.setFormatter(logging.Formatter(FILE_FORMAT))
+
+    root_logger.addHandler(fh)