[gnome-music/wip/mschraal/glib-logging: 7/16] musiclogger: Pass extra fields



commit 3411530f4a6203ef1d926e5326a27f96d6afee13
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 c03d87bd..25e61a6e 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 GLib, GObject
 
 
@@ -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]