nixos/test-driver: enable XML log selectively

Previously, the XML logging was always present and only created an
output file if a special environment variable was present. We now only
create the XML logger if the environment variable is present, saving us
from logging to XML internally if it is not required.
This commit is contained in:
Stefan Hertrampf 2024-04-09 11:20:29 +02:00
parent 9e8d6bbe24
commit 303618c7e1

View File

@ -224,9 +224,8 @@ class TerminalLogger(AbstractLogger):
class XMLLogger(AbstractLogger):
def __init__(self) -> None:
self.logfile = os.environ.get("LOGFILE", "/dev/null")
self.logfile_handle = codecs.open(self.logfile, "wb")
def __init__(self, outfile: str) -> None:
self.logfile_handle = codecs.open(outfile, "wb")
self.xml = XMLGenerator(self.logfile_handle, encoding="utf-8")
self.queue: "Queue[Dict[str, str]]" = Queue()
@ -310,6 +309,4 @@ class XMLLogger(AbstractLogger):
self.xml.endElement("nest")
terminal_logger = TerminalLogger()
xml_logger = XMLLogger()
rootlog: CompositeLogger = CompositeLogger([terminal_logger, xml_logger])
rootlog: CompositeLogger = CompositeLogger([TerminalLogger()])