[gnome-music/wip/mschraal/glib-logging: 9/16] 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: 9/16] musiclogger: Enhance debug and warning messages
- Date: Fri, 31 Jan 2020 11:48:50 +0000 (UTC)
commit 96ce216eb2c9b65aa331f5f7af1ab7131e1f9455
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]