From d08cce497079a9f2143e37a75a01db66438c5dae Mon Sep 17 00:00:00 2001 From: Michael Hudson-Doyle Date: Wed, 11 Dec 2019 13:02:12 +1300 Subject: [PATCH] create an INFO level log file too, unconditionally include it in error reports --- subiquity/cmd/tui.py | 7 +++++-- subiquity/controllers/error.py | 6 +++++- subiquitycore/log.py | 37 ++++++++++++++++++++-------------- 3 files changed, 32 insertions(+), 18 deletions(-) diff --git a/subiquity/cmd/tui.py b/subiquity/cmd/tui.py index 413a1ff3..f65bcb84 100755 --- a/subiquity/cmd/tui.py +++ b/subiquity/cmd/tui.py @@ -109,7 +109,7 @@ def main(): LOGDIR = ".subiquity" if opts.snaps_from_examples is None: opts.snaps_from_examples = True - LOGFILE = setup_logger(dir=LOGDIR) + logfiles = setup_logger(dir=LOGDIR) logger = logging.getLogger('subiquity') logger.info("Starting SUbiquity v{}".format(VERSION)) @@ -142,7 +142,10 @@ def main(): subiquity_interface = Subiquity(opts, block_log_dir) - subiquity_interface.note_file_for_apport("InstallerLog", LOGFILE) + subiquity_interface.note_file_for_apport( + "InstallerLog", logfiles['debug']) + subiquity_interface.note_file_for_apport( + "InstallerLogInfo", logfiles['info']) subiquity_interface.run() diff --git a/subiquity/controllers/error.py b/subiquity/controllers/error.py index 9502feff..877af933 100644 --- a/subiquity/controllers/error.py +++ b/subiquity/controllers/error.py @@ -215,7 +215,11 @@ class ErrorReport(metaclass=urwid.MetaSignals): "Kind": self.kind.value } for k, v in self.pr.items(): - if len(v) < 1024 or k in {"Traceback", "ProcCpuinfoMinimal"}: + if len(v) < 1024 or k in { + "InstallerLogInfo", + "Traceback", + "ProcCpuinfoMinimal", + }: for_upload[k] = v else: log.debug("dropping %s of length %s", k, len(v)) diff --git a/subiquitycore/log.py b/subiquitycore/log.py index 1883e71d..3cac07d8 100644 --- a/subiquitycore/log.py +++ b/subiquitycore/log.py @@ -19,21 +19,28 @@ import os def setup_logger(dir): os.makedirs(dir, exist_ok=True) - nopid_file = os.path.join(dir, "subiquity-debug.log") - LOGFILE = "{}.{}".format(nopid_file, os.getpid()) - handler = logging.FileHandler(LOGFILE, mode='w') - # os.symlink cannot replace an existing file or symlink so create - # it and then rename it over. - tmplink = LOGFILE + ".link" - os.symlink(os.path.basename(LOGFILE), tmplink) - os.rename(tmplink, nopid_file) - - handler.setLevel(logging.DEBUG) - handler.setFormatter( - logging.Formatter( - "%(asctime)s %(levelname)s %(name)s:%(lineno)d %(message)s")) logger = logging.getLogger("") logger.setLevel(logging.DEBUG) - logger.addHandler(handler) - return LOGFILE + + r = {} + + for level in 'info', 'debug': + nopid_file = os.path.join(dir, "subiquity-{}.log".format(level)) + logfile = "{}.{}".format(nopid_file, os.getpid()) + handler = logging.FileHandler(logfile, mode='w') + # os.symlink cannot replace an existing file or symlink so create + # it and then rename it over. + tmplink = logfile + ".link" + os.symlink(os.path.basename(logfile), tmplink) + os.rename(tmplink, nopid_file) + + handler.setLevel(getattr(logging, level.upper())) + handler.setFormatter( + logging.Formatter( + "%(asctime)s %(levelname)s %(name)s:%(lineno)d %(message)s")) + + logger.addHandler(handler) + r[level] = logfile + + return r