-
Notifications
You must be signed in to change notification settings - Fork 701
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
tracing: Add examples to root readme #384
Comments
👍 this seems like a great idea! There are examples in the |
Hi, may I try to solve this issue? I'm currently super curious about tracing and want to do more Rust, so this feels like something very interesting for me personally |
I think that sounds like a great idea. If you do make sure your example includes setting the default log level to info or something |
hi @yaahc , I think I can get this to work. I made quick code like this
But I couldn't get any debug or info message printed in the command line while running the code with |
I'm not sure precisely why its not working, can you remove the Alternatively I recommend using static DEFAULT_FILTER: &str = concat!(module_path!(), "=", "debug"); |
@lunchboxav In your example, you're setting a filter By default, the target of a span or event is the module path of the code it occurs in. I'm assuming your code is not in a file is not called |
Instead of using let subscriber = fmt::Subscriber::builder()
.with_max_level(tracing::Level::DEBUG)
.finish(); |
this is vaguely what I want to see, though I would prefer to see these split up into multiple small snippets that focus on each piece of syntax that I'd want to quickly refer to use tracing::{debug, info, instrument};
use tracing_subscriber::fmt;
// using instrument to setup a span and skip to exclude args
#[instrument(skip(_too_long_string))]
fn count(nums: i32, _too_long_string: &str) -> Vec<i32> {
let mut seq = vec![];
for n in 0..=nums {
// logging n in structured form
debug!(n, "Next Number");
seq.push(n);
}
seq
}
static DEFAULT_FILTER: &str = concat!(module_path!(), "=", "info");
fn main() {
let filter = tracing_subscriber::EnvFilter::try_from_default_env()
.unwrap_or_else(|_| DEFAULT_FILTER.into());
let subscriber = fmt::Subscriber::builder().with_env_filter(filter).finish();
// setup a scoped subscriber
tracing::subscriber::with_default(subscriber, || {
let n = 10;
let sequence = count(n, "I would really prefer this string wasn't in every log");
// standard string interpolation log message
info!("The first {} numbers are {:?}", n, sequence);
})
} |
I believe #496 closed this. |
Feature Request
It's pretty common for crate to have a set of code snippets needed to get started with the least effort possible, and I rely on crates I use having the frequently used syntax in snippets in their main README to advertise this. A good example of this is https://github.com/dtolnay/trybuild
Proposal
We should add a basic example of the minimal set of dependencies and syntax to get setup with tracing including
It may also be helpful to include a screenshot of "Tracing in Action".
The text was updated successfully, but these errors were encountered: