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:
Cargo.toml
[package]
name = "trace-log-target"
version = "0.1.0"
edition = "2021"
[dependencies]
datafusion = "34.0.0"
tokio = "1"
tracing = { version = "0.1", features = ["log"] }
tracing-log = "0.1"
tracing-subscriber = { version = "0.3.18", features = ["json", "env-filter"] }
main.rs
#[tokio::main]
async fn main() {
// Redirecting log events to tracing
tracing_log::LogTracer::init().unwrap();
// Set up the tracing subscriber
let subscriber = tracing_subscriber::FmtSubscriber::builder()
.with_max_level(tracing::Level::DEBUG)
//.json()
.finish();
// Initialize the tracing subscriber
tracing::subscriber::set_global_default(subscriber).expect("setting default subscriber failed");
// Run an external library that uses plain `log`
let ctx = datafusion::execution::context::SessionContext::new();
let df = ctx.sql("SELECT 1").await.unwrap();
df.clone().show().await.unwrap();
}
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)
Feature Request
Crates
tracing-log
Motivation
While the
LogTracer
transmitslog
events, the target field is always set tolog:
, so the original location gets obfuscated.Here's a minimal example:
Cargo.toml
main.rs
Example log line with
cargo run
: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 thelog.target
field)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 thelog.target
that is used in the JSON output format instead of justlog:
, so that I can see something likeAlternatives