diff --git a/anaconda.py b/anaconda.py index 133db87f9b4..b54726119be 100755 --- a/anaconda.py +++ b/anaconda.py @@ -32,16 +32,6 @@ from pyanaconda.modules.common.structures.rescue import RescueData -# Redirect Anaconda main process stderr to Journal, -# as otherwise this could end up writing all over -# the TUI on TTY1. - -# create an appropriately named Journal writing stream -from systemd import journal -anaconda_stderr_stream = journal.stream("anaconda", priority=journal.LOG_ERR) -# redirect stderr of this process to the stream -os.dup2(anaconda_stderr_stream.fileno(), sys.stderr.fileno()) - def exitHandler(rebootData): # Clear the list of watched PIDs. diff --git a/pyanaconda/anaconda_logging.py b/pyanaconda/anaconda_logging.py index 457054cc585..90131176d8d 100644 --- a/pyanaconda/anaconda_logging.py +++ b/pyanaconda/anaconda_logging.py @@ -21,7 +21,7 @@ import logging from logging.handlers import SysLogHandler, SocketHandler -from systemd.journal import JournalHandler +from systemd import journal import os import sys import warnings @@ -94,11 +94,11 @@ def __setattr__(self, name, value): self._stream = WriteProxy() # pylint: disable=attribute-defined-outside-init -class AnacondaJournalHandler(_AnacondaLogFixer, JournalHandler): +class AnacondaJournalHandler(_AnacondaLogFixer, journal.JournalHandler): def __init__(self, tag='', facility=ANACONDA_SYSLOG_FACILITY, identifier=ANACONDA_SYSLOG_IDENTIFIER): self.tag = tag - JournalHandler.__init__(self, + journal.JournalHandler.__init__(self, SYSLOG_FACILITY=facility, SYSLOG_IDENTIFIER=identifier) @@ -106,10 +106,10 @@ def emit(self, record): if self.tag: original_msg = record.msg record.msg = '%s: %s' % (self.tag, original_msg) - JournalHandler.emit(self, record) + journal.JournalHandler.emit(self, record) record.msg = original_msg else: - JournalHandler.emit(self, record) + journal.JournalHandler.emit(self, record) class AnacondaSocketHandler(_AnacondaLogFixer, SocketHandler): @@ -187,6 +187,9 @@ def __init__(self, write_to_journal=False): self.addFileHandler(MAIN_LOG_FILE, simpleline_logger) self.forwardToJournal(simpleline_logger) + # Redirect all stderr messages from process to journal + self.stderrToJournal() + # Create a second logger for just the stuff we want to dup on # stdout. Anything written here will also get passed up to the # parent loggers for processing and possibly be written to the @@ -232,6 +235,17 @@ def forwardToJournal(self, logr, log_formatter=None, log_filter=None): journal_handler.setFormatter(log_formatter) logr.addHandler(journal_handler) + def stderrToJournal(self): + """Print all stderr messages from Anaconda to journal instead. + + Redirect Anaconda main process stderr to Journal, as otherwise this could end up writing + all over the TUI on TTY1. + """ + # create an appropriately named Journal writing stream + anaconda_stderr_stream = journal.stream("anaconda", priority=journal.LOG_ERR) + # redirect stderr of this process to the stream + os.dup2(anaconda_stderr_stream.fileno(), sys.stderr.fileno()) + # pylint: disable=redefined-builtin def showwarning(self, message, category, filename, lineno, file=sys.stderr, line=None):