-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Use env!("CARGO_CRATE_NAME")
in the example to simplify the tracing setup code
#2884
Use env!("CARGO_CRATE_NAME")
in the example to simplify the tracing setup code
#2884
Conversation
0111e70
to
63a42c6
Compare
Interesting idea. Two suggestions:
What do you think? I think together this would look like |
and for |
63a42c6
to
a83c795
Compare
module_path!
macro in the example to simplify the tracing setup codeenv!("CARGO_CRATE_NAME")
in the example to simplify the tracing setup code
I'm afraid that
I do not believe there will be performance issues for our usage scenario. |
examples/error-handling/src/main.rs
Outdated
tracing_subscriber::EnvFilter::try_from_default_env() | ||
.unwrap_or_else(|_| "example_error_handling=debug,tower_http=debug".into()), | ||
tracing_subscriber::EnvFilter::try_from_default_env().unwrap_or_else(|_| { | ||
concat!(env!("CARGO_CRATE_NAME"), "=debug,tower_http=debug").into() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm afraid that concat!(env!("CARGO_CRATE_NAME"), "=debug,tower_http=debug")
is much less clear compared to:
format!("{}=debug,tower_http=debug", env!("CARGO_CRATE_NAME"))
I do not believe there will be performance issues for our usage scenario.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it's a bit ugly. Feel free to change it back.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personally, I'd say having
let crate_name = env!("CARGO_CRATE_NAME");
format!("{crate_name}=debug,tower_http=debug")
would be a more readable alternative, but feel free to ignore this, either is fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
…etup code
Motivation
The example code is full of tracing registration codes, and the log level is hard-coded. I think it can be replaced with the
module_path!
macro.Solution
Simplify the code.