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
This commit is contained in:
David Moreau Simard 2018-06-22 15:36:56 -04:00
parent 87fa84af09
commit c338ae8758
No known key found for this signature in database
GPG Key ID: 33A07694CBB71ECC
1 changed files with 19 additions and 19 deletions

View File

@ -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}'