mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-09-08 00:00:13 +02:00
trace: Remove default trace level and make levels mandatory on span! macro (#1025)
## Motivation Was determined that having the span! macro default to the TRACE level is probably not ideal (see discussion on #952). Closes #1013 ## Solution Remove default trace level and make log lvl mandatory on span! macro, and add the respective `trace_span!`, `debug_span!`, `info_span!`, `warn_span!` and `error_span!` macros that behave as span! macro, but with defined log levels ## Notes I think this is it, also removed some captures that were repeated, and some testcases that also seemed repeated after adding the mandatory log level, but please review it, if more tests or examples are needed happy to provide (tried to find a way to get the generated macros log level, but didn't find one, if there is a way i can add tests to assert that the generated macro has the matching log level ). thanks
This commit is contained in:
committed by
Eliza Weisman
parent
599955f716
commit
597f271c08
@@ -5,7 +5,7 @@ use tokio_trace::{
|
||||
field::{Field, Visit},
|
||||
span,
|
||||
subscriber::{self, Subscriber},
|
||||
Event, Id, Metadata,
|
||||
Event, Id, Level, Metadata,
|
||||
};
|
||||
|
||||
use std::{
|
||||
@@ -125,10 +125,16 @@ fn main() {
|
||||
|
||||
tokio_trace::subscriber::with_default(subscriber, || {
|
||||
let mut foo: u64 = 2;
|
||||
span!("my_great_span", foo_count = &foo).enter(|| {
|
||||
span!(Level::TRACE, "my_great_span", foo_count = &foo).enter(|| {
|
||||
foo += 1;
|
||||
info!({ yak_shaved = true, yak_count = 1 }, "hi from inside my span");
|
||||
span!("my other span", foo_count = &foo, baz_count = 5).enter(|| {
|
||||
span!(
|
||||
Level::TRACE,
|
||||
"my other span",
|
||||
foo_count = &foo,
|
||||
baz_count = 5
|
||||
)
|
||||
.enter(|| {
|
||||
warn!({ yak_shaved = false, yak_count = -1 }, "failed to shave yak");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
#[macro_use]
|
||||
extern crate tokio_trace;
|
||||
|
||||
use tokio_trace::field;
|
||||
use tokio_trace::{field, Level};
|
||||
|
||||
mod sloggish_subscriber;
|
||||
use self::sloggish_subscriber::SloggishSubscriber;
|
||||
@@ -22,16 +22,16 @@ fn main() {
|
||||
let subscriber = SloggishSubscriber::new(2);
|
||||
|
||||
tokio_trace::subscriber::with_default(subscriber, || {
|
||||
span!("", version = &field::display(5.0)).enter(|| {
|
||||
span!("server", host = "localhost", port = 8080).enter(|| {
|
||||
span!(Level::TRACE, "", version = &field::display(5.0)).enter(|| {
|
||||
span!(Level::TRACE, "server", host = "localhost", port = 8080).enter(|| {
|
||||
info!("starting");
|
||||
info!("listening");
|
||||
let mut peer1 = span!("conn", peer_addr = "82.9.9.9", port = 42381);
|
||||
let mut peer1 = span!(Level::TRACE, "conn", peer_addr = "82.9.9.9", port = 42381);
|
||||
peer1.enter(|| {
|
||||
debug!("connected");
|
||||
debug!({ length = 2 }, "message received");
|
||||
});
|
||||
let mut peer2 = span!("conn", peer_addr = "8.8.8.8", port = 18230);
|
||||
let mut peer2 = span!(Level::TRACE, "conn", peer_addr = "8.8.8.8", port = 18230);
|
||||
peer2.enter(|| {
|
||||
debug!("connected");
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user