[meld] Logging adapter for Glib: discard exceptions



commit 9587146dd0148e8720a2b65cd51c19a85692844e
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 4483c5b2..57a7406c 100755
--- a/bin/meld
+++ b/bin/meld
@@ -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
+            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]