rust-lang / log

Logging implementation for Rust
https://docs.rs/log
Apache License 2.0
2.16k stars 250 forks source link

Structured logging doesn't seem to work #540

Closed svanharmelen closed 1 year ago

svanharmelen commented 1 year ago

Hi 👋🏻 I'm trying write structured logs, but somehow the key/values seem to be ignored...

I have this in my Cargo.toml:

[dependencies]
env_logger = "0.10"
log = { version = "0.4.17", features = ["kv_unstable"] }

And this is main.rs:

use log::info;

fn main() {
    env_logger::builder()
        .filter_level(log::LevelFilter::Info)
        .init();
    info!(some = "thing"; "Hello, world!");
}

And when I run this I get this:

image

Any ideas? Am I missing anything or doing something wrong?

Thanks!

Thomasdezeeuw commented 1 year ago

I'm guessing the env_logger crate is not logging the values. You should file an issue here: https://github.com/rust-cli/env_logger.

svanharmelen commented 1 year ago

If that is the case @Thomasdezeeuw, do you know which of the other loggers mentioned in the README does support structured logging?

I was under the impression that this was fully handled in this crate and no additional changed were needed by individual loggers.

Thomasdezeeuw commented 1 year ago

If that is the case @Thomasdezeeuw, do you know which of the other loggers mentioned in the README does support structured logging?

I have my own implementation: https://github.com/Thomasdezeeuw/std-logger. It supports logfmt and JSON (specifically the JSON format used by GCP).

I was under the impression that this was fully handled in this crate and no additional changed were needed by individual loggers.

Key-value logging is experimental, though I think we're pretty close to a stable release. That said, I think individual implementations still need to separately log the key-value pairs as they're exposed a separate field.

svanharmelen commented 1 year ago

Thanks for the pointer @Thomasdezeeuw. Found this one which confirms your guess 😏 So I'll close this issue again...

https://github.com/rust-cli/env_logger/pull/137