GNOME Bugzilla – Bug 771598
overrides/GLib: Add log_structured() - wrapper for g_log_variant()
Last modified: 2016-10-03 22:52:42 UTC
This simplifies JS code for doing structured log: GLib.log_structured('teste', GLib.LogLevelFlags.LEVEL_WARNING, {'MESSAGE': 'Just a test', 'A_FIELD': 'A value'}); Instead of having to create the variant variables by hand.
Created attachment 335770 [details] [review] overrides/GLib: Add log_structured() - wrapper for g_log_variant()
Review of attachment 335770 [details] [review]: seems fine to me. you'll need to also add a dependency in configure.ac on glib 2.50.0. ::: modules/overrides/GLib.js @@ +249,3 @@ + let fields = {}; + for (let key in stringFields) { + fields[key] = new GLib.Variant('s', stringFields[key]); you could potentially throw new TypeError('field is not a string') if typeof stringsFields[key] != 'string' but maybe the new GLib.Variant call already does that for us ? @@ +293,3 @@ }; + + this.log_structured = _log_structured; all the other definitions in _init use assigned anonymous functions. I think your way is cleaner, but it's also not as consistent.
Created attachment 336843 [details] [review] overrides/GLib: Add log_structured() - wrapper for g_log_variant() This simplifies JS code for doing structured log: GLib.log_structured('teste', GLib.LogLevelFlags.LEVEL_WARNING, {'MESSAGE': 'Just a test', 'A_FIELD': 'A value'}); Instead of having to create the variant variables by hand.
(In reply to Ray Strode [halfline] from comment #2) > ::: modules/overrides/GLib.js > @@ +249,3 @@ > + let fields = {}; > + for (let key in stringFields) { > + fields[key] = new GLib.Variant('s', stringFields[key]); > > you could potentially > > throw new TypeError('field is not a string') if typeof stringsFields[key] != > 'string' > > but maybe the new GLib.Variant call already does that for us ? Yep, it raises an error with a stack trace. Example when I used a number: (gjs:26292): Gjs-WARNING **: JS ERROR: Error: Expected type utf8 for Argument 'string' but got type 'number' _pack_variant@resource:///org/gnome/gjs/modules/overrides/GLib.js:104 @resource:///org/gnome/gjs/modules/overrides/GLib.js:261 @resource:///org/gnome/gjs/modules/overrides/GLib.js:289 @test2.js:7
Review of attachment 336843 [details] [review]: Looks good to me.
Attachment 336843 [details] pushed as f934ac9 - overrides/GLib: Add log_structured() - wrapper for g_log_variant()