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



commit e00f400c3cba20cc9c791d9e36aac8dc8bccd9cf
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 1151bc6..013ae70 100755
--- a/bin/meld
+++ b/bin/meld
@@ -237,6 +237,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.
@@ -251,6 +272,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]