Commit 9587146d authored by Vasily Galkin's avatar Vasily Galkin Committed by Kai Willadsen

Logging adapter for Glib: discard exceptions

GLib.log_writer_format_fields has issue on win32 fixing which in glib
can lead to incompatibility issues on all platforms.
See #222 for details.

Since uncaught exceptions in logging may be a bigger problem than
original information going to be logged - just ignore exceptions around
GLib.log_writer_format_fields with trying to pass log to user via
default stdout/stderr handler via GLib.log_writer_standard_streams
parent 885f9250
......@@ -327,9 +327,16 @@ def setup_glib_logging():
# redirection API became a no-op, so we need to hack both of these
# handlers to get it to work.
def structured_log_adapter(level, fields, field_count, user_data):
message = GLib.log_writer_format_fields(level, fields, True)
if not silence(message):
log.log(levels.get(level, logging.WARNING), message)
# Don't even format the message if it will be discarded
py_logging_level = levels.get(level, logging.WARNING)
if log.isEnabledFor(py_logging_level):
# at least glib 2.52 log_writer_format_fields can raise on win32
message = GLib.log_writer_format_fields(level, fields, True)
if not silence(message):
log.log(py_logging_level, message)
except Exception:
GLib.log_writer_standard_streams(level, fields, user_data)
return GLib.LogWriterOutput.HANDLED
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment