[gnome-music/wip/mschraal/glib-logging: 3/11] musiclogger: Pass extra fields



commit d5241a9a9ce35261023ac670fc870736c74d1797
Author: Marinus Schraal <mschraal gnome org>
Date:   Tue Jan 14 16:00:58 2020 +0100

    musiclogger: Pass extra fields
    
    Pass structured fields to the logger, which can be used by logging
    facilities like the systemd journal.

 gnomemusic/musiclogger.py | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)
---
diff --git a/gnomemusic/musiclogger.py b/gnomemusic/musiclogger.py
index 0cf2bd46..2c10c6ac 100644
--- a/gnomemusic/musiclogger.py
+++ b/gnomemusic/musiclogger.py
@@ -22,6 +22,8 @@
 # code, but you are not obligated to do so.  If you do not wish to do so,
 # delete this exception statement from your version.
 
+import inspect
+
 from gi.repository import GObject, GLib
 
 
@@ -35,7 +37,18 @@ class MusicLogger(GObject.GObject):
 
     def _log(self, message, level):
         variant_message = GLib.Variant("s", message)
-        variant_dict = GLib.Variant("a{sv}", {"MESSAGE": variant_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])
+
+        variant_dict = GLib.Variant("a{sv}", {
+            "MESSAGE": variant_message,
+            "CODE_FILE": variant_file,
+            "CODE_LINE": variant_line,
+            "CODE_FUNC": variant_func
+        })
+
         GLib.log_variant(self._DOMAIN, level, variant_dict)
 
     def message(self, message):


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