-
Notifications
You must be signed in to change notification settings - Fork 354
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
@@ -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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
extra newline