[gnome-music/wip/mschraal/glib-logging: 5/11] musiclogger: Enhance debug and warning messages



commit d62b6e35554db8632c3a116c59c899b73e3634d0
Author: Marinus Schraal <mschraal gnome org>
Date:   Wed Jan 15 10:09:28 2020 +0100

    musiclogger: Enhance debug and warning messages
    
    The default log handler prints too little information to be useful.
    
    Add filename, function and line of code to debug and warning messages.

 gnomemusic/musiclogger.py | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)
---
diff --git a/gnomemusic/musiclogger.py b/gnomemusic/musiclogger.py
index 2c10c6ac..d648daf3 100644
--- a/gnomemusic/musiclogger.py
+++ b/gnomemusic/musiclogger.py
@@ -23,6 +23,7 @@
 # delete this exception statement from your version.
 
 import inspect
+import os
 
 from gi.repository import GObject, GLib
 
@@ -36,11 +37,21 @@ class MusicLogger(GObject.GObject):
     _DOMAIN = "org.gnome.Music"
 
     def _log(self, message, level):
-        variant_message = GLib.Variant("s", message)
         stack = inspect.stack()
-        variant_file = GLib.Variant("s", stack[2][1])
-        variant_line = GLib.Variant("i", stack[2][2])
-        variant_func = GLib.Variant("s", stack[2][3])
+
+        filename = os.path.basename(stack[2][1])
+        line = stack[2][2]
+        function = stack[2][3]
+
+        if level in [GLib.LogLevelFlags.LEVEL_DEBUG,
+                     GLib.LogLevelFlags.LEVEL_WARNING]:
+            message = "({}, {}, {}) {}".format(
+                filename, function, line, message)
+
+        variant_message = GLib.Variant("s", message)
+        variant_file = GLib.Variant("s", filename)
+        variant_line = GLib.Variant("i", line)
+        variant_func = GLib.Variant("s", function)
 
         variant_dict = GLib.Variant("a{sv}", {
             "MESSAGE": variant_message,


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