[meld/meld-3-16] bin/meld: Setup glib log handler forwarding to Python logging



commit 137154ed2f6696ef35d5a81a69faade326d8b686
Author: Kai Willadsen <kai willadsen gmail com>
Date:   Sat Sep 24 10:29:29 2016 +1000

    bin/meld: Setup glib log handler forwarding to Python logging
    
    With this change, we hand warning-and-above logs from GTK+ on to our
    Python logger, which gets us some consistency of formatting and
    destination, but most importantly means that we also get to silence
    GTK+ warnings based on whether the running Meld version is stable or
    not.
    
    Effectively, this should silence a lot of noisy complaints about
    missing allocations and size requests not happening where GTK+'s
    expectations have changed and we don't meet them... or the expectations
    aren't actually documented anywhere.

 bin/meld |   22 ++++++++++++++++++++++
 1 files changed, 22 insertions(+), 0 deletions(-)
---
diff --git a/bin/meld b/bin/meld
index aeb9cd3..14aa9e3 100755
--- a/bin/meld
+++ b/bin/meld
@@ -243,6 +243,27 @@ def setup_logging():
     log.addHandler(handler)
 
 
+def setup_glib_logging():
+    from gi.repository import GLib
+    levels = {
+        GLib.LogLevelFlags.LEVEL_WARNING: logging.WARNING,
+        GLib.LogLevelFlags.LEVEL_ERROR: logging.ERROR,
+        GLib.LogLevelFlags.LEVEL_CRITICAL: logging.CRITICAL,
+    }
+    level_flag = (
+        GLib.LogLevelFlags.LEVEL_WARNING |
+        GLib.LogLevelFlags.LEVEL_ERROR |
+        GLib.LogLevelFlags.LEVEL_CRITICAL
+    )
+
+    log_domain = "Gtk"
+    log = logging.getLogger(log_domain)
+
+    def log_adapter(domain, level, message, user_data):
+        log.log(levels[level], message)
+    GLib.log_set_handler(log_domain, level_flag, log_adapter, None)
+
+
 def environment_hacks():
     # We manage cwd ourselves for git operations, and GIT_DIR in particular
     # can mess with this when set.
@@ -257,6 +278,7 @@ if __name__ == '__main__':
     setup_logging()
     disable_stdout_buffering()
     check_requirements()
+    setup_glib_logging()
     setup_resources()
     setup_settings()
     environment_hacks()


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