Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Structured Logging #595

Merged
merged 4 commits into from
Mar 11, 2022
Merged

Structured Logging #595

merged 4 commits into from
Mar 11, 2022

Conversation

jf2048
Copy link
Member

@jf2048 jf2048 commented Mar 9, 2022

Adds bindings for these functions:

  • glib::log_set_writer_func
  • glib::log_structured_array
    • Requires a new GStr wrapper for a borrowed GString, so we can avoid copying the log keys.
  • glib::log_variant
  • glib::log_writer_default
  • glib::log_writer_format_fields
  • glib::log_writer_journald
  • glib::log_writer_standard_streams
  • glib::log_writer_is_journald - unix only
  • glib::log_writer_supports_color - unix only
  • glib::log_writer_default_set_use_stderr
  • glib::log_writer_default_would_drop

And some new macros:

  • glib::gstr - Turns a string literal into a &'static GStr, by appending a nul byte at compile time
  • glib::log_structured - The main interface. From the docs:
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, taking an AsRef<GStr>
        GString::from("MY_FIELD4") => b"a binary string".to_owned();
        // the main log message goes in the MESSAGE field
        "MESSAGE" => "test: {} {}", 1, 2, ;
    }
);

@jf2048 jf2048 marked this pull request as draft March 9, 2022 18:31
@jf2048 jf2048 force-pushed the structured-logging branch 4 times, most recently from 8e8feb8 to 83b05bb Compare March 9, 2022 19:12
@jf2048 jf2048 marked this pull request as ready for review March 9, 2022 20:14
@jf2048 jf2048 force-pushed the structured-logging branch from 83b05bb to 9e1eb06 Compare March 9, 2022 20:27
glib/src/gstring.rs Outdated Show resolved Hide resolved
glib/src/gstring.rs Outdated Show resolved Hide resolved
glib/src/log.rs Outdated Show resolved Hide resolved
glib/src/log.rs Outdated Show resolved Hide resolved
Copy link
Member

@sdroege sdroege left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks nice otherwise

glib/src/log.rs Outdated Show resolved Hide resolved
glib/src/log.rs Outdated Show resolved Hide resolved
glib/src/log.rs Outdated Show resolved Hide resolved
@jf2048 jf2048 force-pushed the structured-logging branch 3 times, most recently from ed5c83e to 690811c Compare March 10, 2022 17:34
@jf2048 jf2048 force-pushed the structured-logging branch from e2ccc37 to 50cc473 Compare March 10, 2022 17:45
@jf2048 jf2048 mentioned this pull request Mar 10, 2022
@sdroege sdroege merged commit 6d59895 into gtk-rs:master Mar 11, 2022
mbiggio pushed a commit to mbiggio/gtk-rs-core that referenced this pull request Mar 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants