Skip to content

Commit a83002b

Browse files
author
Marcin Juszkiewicz
committed
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 (cherry picked from commit 0cf5b1d)
1 parent 3819c16 commit a83002b

File tree

3 files changed

+30
-11
lines changed

3 files changed

+30
-11
lines changed

kolla/common/utils.py

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,33 @@ def make_a_logger(conf=None, image_name=None):
2121
log = logging.getLogger(".".join([__name__, image_name]))
2222
else:
2323
log = logging.getLogger(__name__)
24+
25+
if conf is not None and conf.debug:
26+
loglevel = logging.DEBUG
27+
else:
28+
loglevel = logging.INFO
29+
2430
if not log.handlers:
25-
if conf is None or not conf.logs_dir or not image_name:
26-
handler = logging.StreamHandler(sys.stderr)
27-
log.propagate = False
31+
stream_handler = logging.StreamHandler(sys.stderr)
32+
stream_handler.setFormatter(logging.Formatter(logging.BASIC_FORMAT))
33+
# NOTE(hrw): quiet mode matters only on console
34+
if conf is not None and conf.quiet:
35+
stream_handler.setLevel(logging.CRITICAL)
2836
else:
37+
stream_handler.setLevel(loglevel)
38+
log.addHandler(stream_handler)
39+
log.propagate = False
40+
41+
if conf is not None and conf.logs_dir and image_name:
2942
filename = os.path.join(conf.logs_dir, "%s.log" % image_name)
3043
handler = logging.FileHandler(filename, delay=True)
31-
handler.setFormatter(logging.Formatter(logging.BASIC_FORMAT))
32-
log.addHandler(handler)
33-
if conf is not None and conf.debug:
34-
log.setLevel(logging.DEBUG)
35-
elif conf is not None and conf.quiet and image_name:
36-
log.setLevel(logging.CRITICAL)
37-
else:
38-
log.setLevel(logging.INFO)
44+
# NOTE(hrw): logfile will be INFO or DEBUG
45+
handler.setLevel(loglevel)
46+
handler.setFormatter(logging.Formatter(logging.BASIC_FORMAT))
47+
log.addHandler(handler)
48+
49+
# NOTE(hrw): needs to be high, handlers have own levels
50+
log.setLevel(logging.DEBUG)
3951
return log
4052

4153

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
features:
3+
- |
4+
Quiet mode (enabled with ``--quiet`` argument) can be combined with
5+
``--logs-dir`` option now. Console output will be quiet as expected while
6+
building output will be stored in separate log files.

tests/playbooks/run.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
DEFAULT:
1010
debug: true
1111
logs_dir: "{{ kolla_build_logs_dir }}"
12+
quiet: true
1213
base: "{{ base_distro }}"
1314
install_type: "{{ install_type }}"
1415
template_override: /etc/kolla/template_overrides.j2

0 commit comments

Comments
 (0)