From c338ae8758bdb72daaf9be157bd8470ecfdd4043 Mon Sep 17 00:00:00 2001 From: David Moreau Simard Date: Fri, 22 Jun 2018 15:36:56 -0400 Subject: [PATCH] Logging: don't disable existing loggers, avoid conflicting An issue reported to upstream Ansible [1] highlighted that it was fairly easy for the logging configurations of Ansible and ARA to conflict with each other. This commit makes it so we no longer set the root logger -- we don't need to since we're not expecting orphaned loggers which would inherit from the root configuration. It also makes it so we don't disable existing loggers which would prevent other software from being able to log properly. And finally, it prefixes the names of the handlers and formatters by "ara_" in order to prevent clashing with other software. [1]: https://github.com/ansible/ansible/issues/41838 Change-Id: Iecc3324cc10a767b607d3055d6b93a12b9ae87ee --- ara/config/logger.py | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/ara/config/logger.py b/ara/config/logger.py index eeb14072..5702f919 100644 --- a/ara/config/logger.py +++ b/ara/config/logger.py @@ -27,18 +27,19 @@ from ara.config.compat import ara_config DEFAULT_LOG_CONFIG = """ --- version: 1 +disable_existing_loggers: false formatters: - normal: + ara_standard: format: '%(asctime)s %(levelname)s %(name)s: %(message)s' handlers: - console: + ara_console: class: logging.StreamHandler - formatter: normal + formatter: ara_standard level: INFO stream: ext://sys.stdout - file: + ara_file: class: logging.handlers.TimedRotatingFileHandler - formatter: normal + formatter: ara_standard level: {level} filename: '{dir}/{file}' when: 'midnight' @@ -47,30 +48,26 @@ handlers: loggers: ara: handlers: - - file + - ara_file level: {level} propagate: 0 alembic: handlers: - - console - - file + - ara_console + - ara_file level: WARN propagate: 0 sqlalchemy.engine: handlers: - - file + - ara_file level: WARN propagate: 0 werkzeug: handlers: - - console - - file + - ara_console + - ara_file level: INFO propagate: 0 -root: - handlers: - - file - level: {level} """ @@ -119,11 +116,14 @@ def setup_logging(config=None): ext = os.path.splitext(config['ARA_LOG_CONFIG'])[1] if ext in ('.yml', '.yaml', '.json'): # yaml.safe_load can load json as well as yaml - logging.config.dictConfig(yaml.safe_load( - open(config['ARA_LOG_CONFIG'], 'r') - )) + logging.config.dictConfig( + yaml.safe_load(open(config['ARA_LOG_CONFIG'], 'r')) + ) else: - logging.config.fileConfig(config['ARA_LOG_CONFIG']) + logging.config.fileConfig( + config['ARA_LOG_CONFIG'], + disable_existing_loggers=False + ) logger = logging.getLogger('ara.config.logging') msg = 'Logging: Level {level} from {config}, logging to {dir}/{file}'