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



commit 1473a6dc34836fc7d9282bf7bbba3de1c367926c
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 dc28d151..d7c9e121 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 GLib, GObject
 
@@ -41,11 +42,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]