[gnome-music/wip/mschraal/glib-logging: 21/23] musiclogger: Pass extra fields
- From: Marinus Schraal <mschraal src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-music/wip/mschraal/glib-logging: 21/23] musiclogger: Pass extra fields
- Date: Wed, 15 Jan 2020 09:40:28 +0000 (UTC)
commit bf230a51ff39821fe171315ac7b916c67f03f7c3
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 f43fc26f..fecf929e 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]