diff options
| author | Marcin Juszkiewicz <marcin.juszkiewicz+kolla@linaro.org> | 2022-04-14 15:32:47 +0200 |
|---|---|---|
| committer | Radosław Piliszek <radoslaw.piliszek@gmail.com> | 2022-04-15 13:37:25 +0000 |
| commit | 0cf5b1d4e6e871562c0ca0f48a21594f8d197471 (patch) | |
| tree | 563eda5c337879514fe139480894b26d478c4dc2 | |
| parent | f33ef03977536ecb29ea464b9e557a6caacf4345 (diff) | |
| download | kolla-0cf5b1d4e6e871562c0ca0f48a21594f8d197471.tar.gz kolla-0cf5b1d4e6e871562c0ca0f48a21594f8d197471.zip | |
enable logging to file for quiet mode
We have 'quiet' mode where only minimal data is printed to the console.
But there were no logs at all then.
This change generates log files (if 'logs-dir' argument is used) during
quiet build.
Also enables 'quiet' mode for CI so Zuul will not have to parse 29MB
JSON file each time.
Change-Id: If7d5c2807f0947a8bbbc1ceb8531c9b9c9287c1f
| -rw-r--r-- | kolla/common/utils.py | 34 | ||||
| -rw-r--r-- | releasenotes/notes/quiet-mode-with-logs-0abafc07923945ac.yaml | 6 | ||||
| -rw-r--r-- | tests/playbooks/run.yml | 1 |
3 files changed, 30 insertions, 11 deletions
diff --git a/kolla/common/utils.py b/kolla/common/utils.py index 68996e4b1..4ee80768f 100644 --- a/kolla/common/utils.py +++ b/kolla/common/utils.py @@ -21,21 +21,33 @@ def make_a_logger(conf=None, image_name=None): log = logging.getLogger(".".join([__name__, image_name])) else: log = logging.getLogger(__name__) + + if conf is not None and conf.debug: + loglevel = logging.DEBUG + else: + loglevel = logging.INFO + if not log.handlers: - if conf is None or not conf.logs_dir or not image_name: - handler = logging.StreamHandler(sys.stderr) - log.propagate = False + stream_handler = logging.StreamHandler(sys.stderr) + stream_handler.setFormatter(logging.Formatter(logging.BASIC_FORMAT)) + # NOTE(hrw): quiet mode matters only on console + if conf is not None and conf.quiet: + stream_handler.setLevel(logging.CRITICAL) else: + stream_handler.setLevel(loglevel) + log.addHandler(stream_handler) + log.propagate = False + + if conf is not None and conf.logs_dir and image_name: filename = os.path.join(conf.logs_dir, "%s.log" % image_name) handler = logging.FileHandler(filename, delay=True) - handler.setFormatter(logging.Formatter(logging.BASIC_FORMAT)) - log.addHandler(handler) - if conf is not None and conf.debug: - log.setLevel(logging.DEBUG) - elif conf is not None and conf.quiet and image_name: - log.setLevel(logging.CRITICAL) - else: - log.setLevel(logging.INFO) + # NOTE(hrw): logfile will be INFO or DEBUG + handler.setLevel(loglevel) + handler.setFormatter(logging.Formatter(logging.BASIC_FORMAT)) + log.addHandler(handler) + + # NOTE(hrw): needs to be high, handlers have own levels + log.setLevel(logging.DEBUG) return log diff --git a/releasenotes/notes/quiet-mode-with-logs-0abafc07923945ac.yaml b/releasenotes/notes/quiet-mode-with-logs-0abafc07923945ac.yaml new file mode 100644 index 000000000..1b8e67855 --- /dev/null +++ b/releasenotes/notes/quiet-mode-with-logs-0abafc07923945ac.yaml @@ -0,0 +1,6 @@ +--- +features: + - | + Quiet mode (enabled with ``--quiet`` argument) can be combined with + ``--logs-dir`` option now. Console output will be quiet as expected while + building output will be stored in separate log files. diff --git a/tests/playbooks/run.yml b/tests/playbooks/run.yml index 5bd494afd..9b544b30f 100644 --- a/tests/playbooks/run.yml +++ b/tests/playbooks/run.yml @@ -8,6 +8,7 @@ DEFAULT: debug: true logs_dir: "{{ kolla_build_logs_dir }}" + quiet: true base: "{{ base_distro }}" template_override: /etc/kolla/template_overrides.j2 # NOTE(yoctozepto): to avoid issues with IPv6 not enabled in the docker daemon |
