From: Thanh Ha Date: Fri, 24 Aug 2018 01:23:18 +0000 (-0400) Subject: Simplify logging configuration X-Git-Tag: v0.16.0~3 X-Git-Url: https://gerrit.linuxfoundation.org/infra/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F78%2F12378%2F3;p=releng%2Flftools.git Simplify logging configuration 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 --- diff --git a/etc/logging.ini b/etc/logging.ini deleted file mode 100644 index 293a14b8..00000000 --- a/etc/logging.ini +++ /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= diff --git a/lftools/__init__.py b/lftools/__init__.py index 5ef90fbe..2754d0c8 100644 --- a/lftools/__init__.py +++ b/lftools/__init__.py @@ -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 index 00000000..435c95a5 --- /dev/null +++ b/releasenotes/notes/logger-1aa26520f6d39fcb.yaml @@ -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. diff --git a/setup.cfg b/setup.cfg index 4c3a91c4..fb66dae0 100644 --- 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