macro_rules! log_structured {
    ($log_domain:expr, $log_level:expr, {$($key:expr => $format:expr $(,$arg:expr)* $(,)?);+ $(;)?} $(,)?) => { ... };
}
Expand description

Macro used to log using GLib structured logging system.

The structured data is provided inside braces as key-value pairs using the => token and separated by semicolons. The key can be a string literal or an expression that satisfies AsRef<GStr>. The value can be a format string with arguments, or a single expression that satisfies AsRef<[u8]>.

See g_log_structured for more details.

Example:

use glib::{GString, LogLevel, log_structured};
use std::ffi::CString;

log_structured!(
    "test",
    LogLevel::Debug,
    {
        // a normal string field
        "MY_FIELD" => "123";
        // fields can also take format arguments
        "MY_FIELD2" => "abc {}", "def";
        // single argument can be a &str or a &[u8] or anything else satsfying AsRef<[u8]>
        "MY_FIELD3" => CString::new("my string").unwrap().to_bytes();
        // field names can also be dynamic
        GString::from("MY_FIELD4") => b"a binary string".to_owned();
        // the main log message goes in the MESSAGE field
        "MESSAGE" => "test: {} {}", 1, 2, ;
    }
);