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

Support structured logging (KV) #77

Draft
wants to merge 8 commits into
base: main-dev
Choose a base branch
from
Draft

Support structured logging (KV) #77

wants to merge 8 commits into from

Conversation

SpriteOvO
Copy link
Owner

@SpriteOvO SpriteOvO commented Nov 23, 2024

Implementation of #70, working in progress.

Steps

  • Add kv::Key and kv::Value
    • Let's try using value-bag directly (alias) for value first.
  • Add kvs field to struct Record.
  • Logging macros accepts kv optional parameter.
    • I plan to use this syntax
      info!(kv: { a = 1, b = 2 }, "payload {}", 123);
      info!("payload {}", 123, kv: { a = 1, b = 2 });
      The kv is optional, just like the existing logger argument, and I may wish to allow them to be in any order. The colon allows us to distinguish with the formatting arguments so that it can be placed anywhere.
    • We can consider whether the following more advanced usages will be supported in this PR or in the future, but these syntaxes have not yet been decided.
      let key = "a";
      info!(kv: { {key} = 1, b = 2 }, "payload {}", 123);
      
      let kvs = HashMap::from_iter([("a", 1), ("b", 2)]);
      info!(kv: kvs, "payload {}", 123);
  • Add tests.
  • Support it in FullFormatter.
  • Support it in PatternFormatter.
    • How to design placeholders for KV? - Simply adding a new {kv} pattern to output like "{ k1=1, k2=text }"
  • Serialize KVs to a separated kv field in JsonFormatter.
  • Key modifier in macros.
    info!(kv: { k1: = value, k2:? = value }, "message"); // "message { k1=display, k2=debug }"
  • Shorhand in macros.
    let num = 123;
    info!(kv: { num }, "message"); // "message { num=123 }"
  • Support parameter arbitrary ordering. (might require to refactor it in proc-macro)
  • Try to replace slice with phf map for KV. (self-reminder: benchmarking it..)
  • Add documentation and examples (macros, accessing in Record, downcasting, etc.).

@SpriteOvO SpriteOvO changed the title Add basic support for structured logging (KV) Support structured logging (KV) Nov 23, 2024
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.

1 participant