diff --git a/anaconda.py b/anaconda.py index 821690d5a0c..5034f9717ca 100755 --- a/anaconda.py +++ b/anaconda.py @@ -169,6 +169,7 @@ def setup_environment(): if "EDITOR" not in os.environ and os.path.isfile("/etc/profile.d/nano-default-editor.sh"): os.environ["EDITOR"] = "/usr/bin/nano" + if __name__ == "__main__": # check if the CLI help is requested and return it at once, # without importing random stuff and spamming stdout diff --git a/pyanaconda/anaconda_logging.py b/pyanaconda/anaconda_logging.py index 5c86de610ff..b96cabb2dd6 100644 --- a/pyanaconda/anaconda_logging.py +++ b/pyanaconda/anaconda_logging.py @@ -29,6 +29,10 @@ from pyanaconda.core import constants from pyanaconda.core.path import set_mode +import gi +gi.require_version("GLib", "2.0") +from gi.repository import GLib + ENTRY_FORMAT = "%(asctime)s,%(msecs)03d %(levelname)s %(name)s: %(message)s" STDOUT_FORMAT = "%(asctime)s %(message)s" DATE_FORMAT = "%H:%M:%S" @@ -187,8 +191,8 @@ 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() + # Redirect GLib logging (eq. GTK) to Journal + self.redirect_glib_logging_to_journal() # Create a second logger for just the stuff we want to dup on # stdout. Anything written here will also get passed up to the @@ -235,19 +239,35 @@ 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. + def redirect_glib_logging_to_journal(self): + """Redirect GLib based library logging to Journal. + + Some GLib based libraries (such as GTK) do direct their + sometimes quite verbose log messages to the output of the + proces in which they are running. In the Anaconda case, + this creates issues with TTY1 being spammed with those + messages, with important content (such RDP connection intructions) + being scrolled out of view. - Redirect Anaconda main process stderr to Journal, as otherwise this could end up writing - all over the TUI on TTY1. + :param log: anaconda log handler """ + if not self.write_to_journal: return - # 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()) + # create functions that convert the messages comming + # from GLib into something that fits to the PYthon logging format + def log_adapter(domain, level, message, user_data): + self.anaconda_logger.debug("GLib: %s", message) + + def structured_log_adapter(level, fields, field_count, user_data): + message = GLib.log_writer_format_fields(level, fields, True) + self.anaconda_logger.debug("GLib: %s", message) + return GLib.LogWriterOutput.HANDLED + + # redirect GLib loug output vit the functions + GLib.log_set_handler(None, GLib.LogLevelFlags.LEVEL_MASK, log_adapter, None) + GLib.log_set_writer_func(structured_log_adapter, None) # pylint: disable=redefined-builtin def showwarning(self, message, category, filename, lineno,