Re: g_log_structured() and introspection
- From: Emmanuele Bassi <ebassi gmail com>
- To: Ray Strode <halfline gmail com>
- Cc: desktop-devel-list <desktop-devel-list gnome org>
- Subject: Re: g_log_structured() and introspection
- Date: Sat, 13 Aug 2016 08:03:13 +0100
Hi;
I actually like the idea of a GVariant based API, so +1 from me.
Ciao,
Emmanuele.
On Saturday, 13 August 2016, Ray Strode <
halfline gmail com> wrote:
Hey,
> During the talk on GLib's new structured logging API at GUADEC today,
> it was pointed out that g_log_structured() (and the rest of the
> interesting bits of the new structured logging API) are not
> introspectable.
>
> I'm not sure what we can do about this. The API is based around
> GLogField, which is basically a pointer and a length, and hence is not
> introspectable:
>
> struct _GLogField
> {
> const gchar *key;
> gconstpointer value;
> gssize length;
> };
One idea:
1) g_log_variant (GLogLevelFlags log_level, GVariant *variant);
The variant would have to be of type G_VARIANT_TYPE_VARDICT
In _javascript_ for instance it could look like this:
fields = { 'MESSAGE': new GLib.Variant('s', 'checking for optional
sweep modulation'),
'GLIB_DOMAIN': new GLib.Variant('s', 'Foo'),
'FOO_STATE': new GLib.Variant('s', JSON.stringify(fooState)),
'FOO_AGE': new GLib.Variant('u', 3) };
GLib.log_variant(GLib.LogLevelFlags.level_debug, new
GLib.Variant('a{sv}', fields))
which is a little wordy, but not more awful than how dbus is done.
Then Gjs could ship a string only convenience
api like g_log_structured by doing:
GLib.log_structured = function(logDomain, logLevel, stringFields) = {
fields = {};
for (let key in stringFields) {
fields[key] = new GLib.Variant('s', stringFields[key]);
}
fields['GLIB_DOMAIN'] = new GLib.Variant('s', logDomain);
GLib.log_variant(logLevel, new GLib.Variant('a{sv}', fields);
}
then the _javascript_ would be:
GLib.log_structured(GLib.LogLevelFlags.level_debug,
{ 'MESSAGE': 'checking for optional sweep
modulation',
'FOO_STATE': JSON.stringify(fooState)});
(or it could make it variadic like g_log_structured, but that's less
idiomatic for our brand of _javascript_)
One complication with g_log_variant, is figuring out how to send the
variant off to journald. If you just use g_variant_print, you'll end
up putting quotes around all the strings, which is probably wrong.
It's probably have to unpack the variant manually, with fall back to
g_variant_print
anyway, just an idea.
_______________________________________________
desktop-devel-list mailing list
desktop-devel-list gnome org
https://mail.gnome.org/mailman/listinfo/desktop-devel-list
--
https://www.bassi.io[@] ebassi [@
gmail.com]
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]