[gnome-music/wip/mschraal/glib-logging: 7/65] musiclogger: Enhance debug and warning messages
- From: Marinus Schraal <mschraal src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-music/wip/mschraal/glib-logging: 7/65] musiclogger: Enhance debug and warning messages
- Date: Sat, 1 Feb 2020 15:17:01 +0000 (UTC)
commit f1d6fa8b694da9b6389fa6f15f38d5d897367a78
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 25e61a6e..8bdd9b0a 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
@@ -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]