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=<extension@uuid>

https://bugzilla.gnome.org/show_bug.cgi?id=770717
This commit is contained in:
Jonh Wendell 2016-10-03 20:09:39 -03:00
parent c405081d89
commit 70526a8025
2 changed files with 15 additions and 6 deletions

View File

@ -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

View File

@ -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;