Simplify logging configuration 78/12378/3
authorThanh Ha <thanh.ha@linuxfoundation.org>
Fri, 24 Aug 2018 01:23:18 +0000 (21:23 -0400)
committerThanh Ha <thanh.ha@linuxfoundation.org>
Fri, 24 Aug 2018 03:22:49 +0000 (23:22 -0400)
lftools should be a simple tool and folks should not ever need to
configure the logger so let's simplify things and just pre-define
an acceptable logger configuration. The important component is
having (DEBUG) messages print via logger service. A subsequent
patch will be provided to enable --debug level logs via CLI.

Change-Id: I74158d94400112161ad4fc206426420d908deb0c
Signed-off-by: Thanh Ha <thanh.ha@linuxfoundation.org>
etc/logging.ini [deleted file]
lftools/__init__.py
releasenotes/notes/logger-1aa26520f6d39fcb.yaml [new file with mode: 0644]
setup.cfg

diff --git a/etc/logging.ini b/etc/logging.ini
deleted file mode 100644 (file)
index 293a14b..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-[loggers]
-keys=root
-
-[handlers]
-keys=consoleHandler
-
-[formatters]
-keys=simpleFormatter
-
-[logger_root]
-level=DEBUG
-handlers=consoleHandler
-
-[handler_consoleHandler]
-class=StreamHandler
-level=INFO
-formatter=simpleFormatter
-args=(sys.stdout,)
-
-[formatter_simpleFormatter]
-format=%(asctime)s (%(levelname)s) %(name)s: %(message)s
-datefmt=
index 5ef90fb..2754d0c 100644 (file)
@@ -18,48 +18,9 @@ __version__ = '0.16.0-dev'
 
 import logging
 import logging.config
-import os
-import sys
 
-log = logging.getLogger(__name__)
-
-
-def find_log_ini(file_name='logging.ini'):
-    """Find the logging.ini file.
-
-    Precedence:
-        1) ~/.config/lftools/logging.ini
-        2) /etc/lftools/logging.ini
-        3) sys.prefix/etc/logging.ini
-
-        Dev only...
-        4) etc/logging.ini (Default fallback in dev environments)
-    """
-    homedir = os.path.expanduser('~')
-    log_file_etc = os.path.abspath(os.path.join('/etc', 'lftools', file_name))
-    log_file_home = os.path.abspath(os.path.join(homedir, '.config', 'lftools', file_name))
-    log_file_pyprefix = os.path.abspath(os.path.join(sys.prefix, 'etc', file_name))
-
-    if os.path.exists(log_file_home):
-        file_path = log_file_home
-    elif os.path.exists(log_file_etc):
-        file_path = log_file_etc
-    elif os.path.exists(log_file_pyprefix):
-        file_path = log_file_pyprefix
-    else:
-        file_path = os.path.join('etc', file_name)
-    return file_path
-
-
-log_ini_file = find_log_ini()
-
-if os.path.exists(log_ini_file):
-    logging.config.fileConfig(log_ini_file)
-    log.info("Using logger config file {}".format(log_ini_file))
-else:
-    formatter = logging.Formatter('%(asctime)s (%(levelname)s) %(name)s: %(message)s')
-    console_handler = logging.StreamHandler()
-    console_handler.setFormatter(formatter)
-    logging.getLogger("").setLevel(logging.NOTSET)
-    logging.getLogger("").addHandler(console_handler)
-    log.info("Log ini file not found. Using a default logger...")
+formatter = logging.Formatter('(%(levelname)s) %(name)s: %(message)s')
+console_handler = logging.StreamHandler()
+console_handler.setFormatter(formatter)
+logging.getLogger("").setLevel(logging.NOTSET)
+logging.getLogger("").addHandler(console_handler)
diff --git a/releasenotes/notes/logger-1aa26520f6d39fcb.yaml b/releasenotes/notes/logger-1aa26520f6d39fcb.yaml
new file mode 100644 (file)
index 0000000..435c95a
--- /dev/null
@@ -0,0 +1,6 @@
+---
+deprecations:
+  - |
+    Remove support for modifying the logger via logging.ini. It was a good idea
+    but in practice this is not really used and adds extra complexity to
+    lftools.
index 4c3a91c..fb66dae 100644 (file)
--- a/setup.cfg
+++ b/setup.cfg
@@ -28,9 +28,6 @@ openstack =
 
 [files]
 packages = lftools
-data_files =
-    etc =
-        etc/logging.ini
 scripts =
     shell/dco
     shell/deploy