Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redirect only GLib loggers to Journal #5962

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions anaconda.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extra newline

if __name__ == "__main__":
# check if the CLI help is requested and return it at once,
# without importing random stuff and spamming stdout
Expand Down
40 changes: 30 additions & 10 deletions pyanaconda/anaconda_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/eq./e.g.,/

looks like this file uses camelCase for function names? All of your new functions seem to use underscores


# Create a second logger for just the stuff we want to dup on
# stdout. Anything written here will also get passed up to the
Expand Down Expand Up @@ -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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's usually called "the journal" not "Journal", but I guess it doesn't really matter

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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/proces/process/

this creates issues with TTY1 being spammed with those
messages, with important content (such RDP connection intructions)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/such RDP connection intructions/such as RDP connection instructions/

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
Comment on lines +258 to +259
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/comming/ s/PYthon/python/

It's not actually a python logging format but the anaconda logging format right?

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/loug/log/ s/vit/via/

GLib.log_set_handler(None, GLib.LogLevelFlags.LEVEL_MASK, log_adapter, None)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i wonder if it would be clearer to give the individual log levels instead of using the mask wholesale. doesn't really matter, but food for thought.

GLib.log_set_writer_func(structured_log_adapter, None)

# pylint: disable=redefined-builtin
def showwarning(self, message, category, filename, lineno,
Expand Down