Commit 51f89902 authored by Yusei Tahara's avatar Yusei Tahara

slapos/cli/entry.py, slapos/cli/format.py, slapos/format.py: Do not double the...

slapos/cli/entry.py, slapos/cli/format.py, slapos/format.py: Do not double the log output when "slapos node boot" failed.
parent cc2fbe03
......@@ -239,6 +239,13 @@ class SlapOSApp(App):
root_logger.addHandler(file_handler)
# Always send higher-level messages to the console via stderr
# This function is called again if "slapos node boot" failed.
# Don't add a handler again, otherwise the output becomes double.
if [handler for handler in root_logger.handlers
if isinstance(handler, logging.StreamHandler)]:
return
if self.options.log_color:
import coloredlogs
console = coloredlogs.ColoredStreamHandler(show_name=True, # logger name (slapos) and PID
......
......@@ -98,7 +98,10 @@ class FormatCommand(ConfigCommand):
if string_to_boolean(getattr(conf, 'root_check', 'True').lower()):
check_root_user(self)
if not self.app.options.log_file and conf.log_file:
if len(self.app.log.handlers) == 0 and not self.app.options.log_file and conf.log_file:
# This block is called again if "slapos node boot" failed.
# Don't add a handler again, otherwise the output becomes double.
#
# no log file is provided by argparser,
# we set up the one from config
file_handler = logging.FileHandler(conf.log_file)
......
......@@ -1422,8 +1422,15 @@ class FormatConfig(object):
self.output_definition_file = os.path.abspath(self.output_definition_file)
tracing_monkeypatch_mark = []
def tracing_monkeypatch(conf):
"""Substitute os module and callAndRead function with tracing wrappers."""
# This function is called again if "slapos node boot" failed.
# Don't wrap the logging method again, otherwise the output becomes double.
if tracing_monkeypatch_mark:
return
global os
global callAndRead
......@@ -1452,3 +1459,5 @@ def tracing_monkeypatch(conf):
return dry_callAndRead(argument_list, raise_on_error)
callAndRead = logging_callAndRead
# Put a mark. This function was called once.
tracing_monkeypatch_mark.append(None)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment