tokio-rs / tracing

Application level tracing for Rust.
https://tracing.rs
MIT License
5.4k stars 709 forks source link

Enable overriding `target` field with `log`'s target in `LogTracer` #2862

Closed gruuya closed 8 months ago

gruuya commented 8 months ago

Feature Request

Crates

tracing-log

Motivation

While the LogTracer transmits log events, the target field is always set to log:, so the original location gets obfuscated.

Here's a minimal example:

Example log line with cargo run:

2024-01-25T08:46:42.249999Z DEBUG log: Plan unchanged by optimizer rule 'eliminate_limit' (pass 0)

Note that the target just says log:, which can get pretty confusing when trying to troubleshoot logs from many libraries.

However, if I uncomment the .json() line above I see that the actual target info is still present, albeit nested (datafusion_optimizer::optimizer from the log.target field)

{"timestamp":"2024-01-24T11:26:30.372803Z","level":"DEBUG","fields":{"message":"Plan unchanged by optimizer rule 'eliminate_limit' (pass 0)","log.target":"datafusion_optimizer::optimizer","log.module_path":"datafusion_optimizer::optimizer","log.file":"/Users/gruuya/.cargo/registry/src/index.crates.io-6f17d22bba15001f/datafusion-optimizer-34.0.0/src/optimizer.rs","log.line":309},"target":"log","threadName":"tokio-runtime-worker","threadId":"ThreadId(11)"}

Proposal

I'd like to be able to configure the LogTracer if possible (or something else) such that the target in the default output format prints out the log.target that is used in the JSON output format instead of just log:, so that I can see something like

2024-01-25T08:46:42.249999Z DEBUG datafusion_optimizer::optimizer: Plan unchanged by optimizer rule 'eliminate_limit' (pass 0)

Alternatives

gruuya commented 8 months ago

Oh, I see that bumping to tracing-log 0.2 solves the issue.