diff options
author | Monty Taylor <mordred@inaugust.com> | 2017-08-25 19:14:25 -0500 |
---|---|---|
committer | Monty Taylor <mordred@inaugust.com> | 2017-08-28 20:06:10 -0500 |
commit | 7093b49f04d086a17a640b6f18ed47159cfe1dc3 (patch) | |
tree | 537685c73048d03b78b1a69f9a4098689e7fa110 /zuul/ansible/callback | |
parent | 22dd6506f4dd684f8c6e497c09f4bf64b82a9150 (diff) | |
download | zuul-7093b49f04d086a17a640b6f18ed47159cfe1dc3.tar.gz |
Write a logging config file and pass it to callbacks
We need to pass a working logging config to zuul_stream and ara so that
alembic migrations don't step on pre-playbook output.
Write a logging config using json, then pass its location in env vars so that
zuul_stream and ara can pick it up and pass it to dictConfig.
In support of this, create a LoggingConfig class so that we don't have
to copy key names and logic between executor.server, zuul_stream and
zuul_json. Since we have one, go ahead and use it for the server logging
config too, providing them with a slightly richer default logging
config for folks who don't provide a logging config file of their own.
The log config processing has to go into zuul.ansible because it's
needed in the bubblewrap and we don't have it in the python path
otherwise.
Change-Id: I3d7ac797fd2ee2c53f5fbd79d3ee048be6ca9366
Diffstat (limited to 'zuul/ansible/callback')
-rw-r--r-- | zuul/ansible/callback/zuul_json.py | 8 | ||||
-rw-r--r-- | zuul/ansible/callback/zuul_stream.py | 16 |
2 files changed, 16 insertions, 8 deletions
diff --git a/zuul/ansible/callback/zuul_json.py b/zuul/ansible/callback/zuul_json.py index 612a72069..222302c8d 100644 --- a/zuul/ansible/callback/zuul_json.py +++ b/zuul/ansible/callback/zuul_json.py @@ -33,6 +33,8 @@ except ImportError: # It's here in 2.3 from ansible.vars.manager import strip_internal_keys +from zuul.ansible import logconfig + class CallbackModule(CallbackBase): CALLBACK_VERSION = 2.0 @@ -45,8 +47,12 @@ class CallbackModule(CallbackBase): self.results = [] self.output = [] self.playbook = {} + logging_config = logconfig.load_job_config( + os.environ['ZUUL_JOB_LOG_CONFIG']) + self.output_path = os.path.splitext( - os.environ['ZUUL_JOB_OUTPUT_FILE'])[0] + '.json' + logging_config.job_output_file)[0] + '.json' + # For now, just read in the old file and write it all out again # This may well not scale from a memory perspective- but let's see how # it goes. diff --git a/zuul/ansible/callback/zuul_stream.py b/zuul/ansible/callback/zuul_stream.py index 4cfd19ea2..19b11921d 100644 --- a/zuul/ansible/callback/zuul_stream.py +++ b/zuul/ansible/callback/zuul_stream.py @@ -21,6 +21,7 @@ from __future__ import absolute_import import datetime import logging +import logging.config import json import os import socket @@ -30,6 +31,8 @@ import uuid from ansible.plugins.callback import default +from zuul.ansible import logconfig + LOG_STREAM_PORT = 19885 @@ -108,14 +111,13 @@ class CallbackModule(default.CallbackModule): # ansible appends timestamp, user and pid to the log lines emitted # to the log file. We're doing other things though, so we don't want # this. - path = os.environ['ZUUL_JOB_OUTPUT_FILE'] + logging_config = logconfig.load_job_config( + os.environ['ZUUL_JOB_LOG_CONFIG']) + if self._display.verbosity > 2: - level = logging.DEBUG - else: - level = logging.INFO - logging.basicConfig(filename=path, level=level, format='%(message)s') - # Squelch logging from ara so we don't get the initializing message - logging.getLogger('ara').setLevel(logging.ERROR) + logging_config.setDebug() + + logging_config.apply() self._logger = logging.getLogger('zuul.executor.ansible') |