create an INFO level log file too, unconditionally include it in error reports

This commit is contained in:
Michael Hudson-Doyle 2019-12-11 13:02:12 +13:00
parent 7a447c7e38
commit d08cce4970
3 changed files with 32 additions and 18 deletions

View File

@ -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()

View File

@ -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))

View File

@ -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