[gjs] overrides/GLib: Add log_structured() - wrapper for g_log_variant()



commit f934ac93c2dc064943b595e91fda227b80125f62
Author: Jonh Wendell <jonh wendell redhat com>
Date:   Mon Oct 3 19:02:52 2016 -0300

    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.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=771598

 configure.ac              |    2 +-
 modules/overrides/GLib.js |   10 ++++++++++
 2 files changed, 11 insertions(+), 1 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index a13bc89..ce1cbb1 100644
--- a/configure.ac
+++ b/configure.ac
@@ -49,7 +49,7 @@ AX_CHECK_LINK_FLAG([-lgcov],, [
 ])
 
 # Checks for libraries.
-m4_define(glib_required_version, 2.42.0)
+m4_define(glib_required_version, 2.50.0)
 
 GOBJECT_INTROSPECTION_REQUIRE([1.41.4])
 
diff --git a/modules/overrides/GLib.js b/modules/overrides/GLib.js
index f4161a2..70528c3 100644
--- a/modules/overrides/GLib.js
+++ b/modules/overrides/GLib.js
@@ -282,4 +282,14 @@ function _init() {
     this.Bytes.prototype.toArray = function() {
        return imports.byteArray.fromGBytes(this);
     };
+
+    this.log_structured = function(logDomain, logLevel, stringFields) {
+        let fields = {};
+        for (let key in stringFields) {
+            fields[key] = new GLib.Variant('s', stringFields[key]);
+        }
+
+        GLib.log_variant(logDomain, logLevel, new GLib.Variant('a{sv}', fields));
+    };
+
 }


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