From 70526a80251b0f4c48144b389d741025715efbb6 Mon Sep 17 00:00:00 2001 From: Jonh Wendell Date: Mon, 3 Oct 2016 20:09:39 -0300 Subject: [PATCH] log(): Reimplement on top of GLib.log_structured This allows us to pass metadata fields besides the message to log. So, if the log() call is made from an extension, pass the extension name and UUID to the logger. This is useful for extension developers to debug their code as well as to instruct their users to send debug info to them by running something like this: journalctl GNOME_SHELL_EXTENSION_UUID= https://bugzilla.gnome.org/show_bug.cgi?id=770717 --- configure.ac | 2 +- js/ui/environment.js | 19 ++++++++++++++----- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/configure.ac b/configure.ac index 7d47643f5..b436a8652 100644 --- a/configure.ac +++ b/configure.ac @@ -77,7 +77,7 @@ AC_MSG_RESULT($enable_systemd) CLUTTER_MIN_VERSION=1.21.5 GOBJECT_INTROSPECTION_MIN_VERSION=1.49.1 -GJS_MIN_VERSION=1.39.0 +GJS_MIN_VERSION=1.47.0 MUTTER_MIN_VERSION=3.22.1 GTK_MIN_VERSION=3.15.0 GIO_MIN_VERSION=2.45.3 diff --git a/js/ui/environment.js b/js/ui/environment.js index 6fb23e353..68ddaa783 100644 --- a/js/ui/environment.js +++ b/js/ui/environment.js @@ -61,10 +61,19 @@ function _patchLayoutClass(layoutClass, styleProps) { }; } -function _makeLoggingFunc(func) { - return function() { - return func([].join.call(arguments, ', ')); - }; +function _loggingFunc() { + let fields = {'MESSAGE': [].join.call(arguments, ', ')}; + let domain = "GNOME Shell"; + + // If the caller is an extension, add it as metadata + let extension = imports.misc.extensionUtils.getCurrentExtension(); + if (extension != null) { + domain = extension.metadata.name; + fields['GNOME_SHELL_EXTENSION_UUID'] = extension.uuid; + fields['GNOME_SHELL_EXTENSION_NAME'] = extension.metadata.name; + } + + GLib.log_structured(domain, GLib.LogLevelFlags.LEVEL_MESSAGE, fields); } function init() { @@ -72,7 +81,7 @@ function init() { // browser convention of having that namespace be called 'window'.) window.global = Shell.Global.get(); - window.log = _makeLoggingFunc(window.log); + window.log = _loggingFunc; window._ = Gettext.gettext; window.C_ = Gettext.pgettext;