[meld/meld-3-18: 1/2] Logging adapter for Glib: discard exceptions



commit 862eb7dcd8dd670c12a1e888c632180b1d797c57
Author: Vasily Galkin <galkin-vv ya ru>
Date:   Sun Sep 30 01:01:05 2018 +0300

    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 GNOME/meld#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

 bin/meld | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)
---
diff --git a/bin/meld b/bin/meld
index e3a12380..8e19a587 100755
--- a/bin/meld
+++ b/bin/meld
@@ -325,9 +325,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
+            try:
+                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
 
     try:


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]