Re: g_log_structured() and introspection


On Sat, 2016-08-13 at 01:49 -0400, Ray Strode wrote:

During the talk on GLib's new structured logging API at GUADEC
it was pointed out that g_log_structured() (and the rest of the
interesting bits of the new structured logging API) are not

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

    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',
              '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:

                             { 'MESSAGE': 'checking for optional

Seems reasonable to me. pygobject, gjs people: how does that look to

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

Yeah, the conversion from each a{sv} value to a GLogField value would
be the least satisfying part: I guess we'd do something like:
  if it's a string: use the string directly
  if it's a byte array ('ay'): use the byte array with its length
  if it's anything else: g_variant_print() and hope it looks reasonable


Attachment: signature.asc
Description: This is a digitally signed message part

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]