Skip to content

Commit

Permalink
- remove default trace level and make log lvl mandatory on span! macro
Browse files Browse the repository at this point in the history
- add trace_span!, debug_span!, info_span!, warn_span! and error_span!
macros that behave as span! macro, but with defined log levels
  • Loading branch information
jxs committed Mar 31, 2019
1 parent cb91dd2 commit 89ffd06
Show file tree
Hide file tree
Showing 9 changed files with 759 additions and 162 deletions.
10 changes: 8 additions & 2 deletions tokio-trace/examples/counters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(tokio_trace::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!(
tokio_trace::Level::TRACE,
"my other span",
foo_count = &foo,
baz_count = 5
)
.enter(|| {
warn!({ yak_shaved = false, yak_count = -1 }, "failed to shave yak");
});
});
Expand Down
29 changes: 25 additions & 4 deletions tokio-trace/examples/sloggish/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,37 @@ 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!(
tokio_trace::Level::TRACE,
"",
version = &field::display(5.0)
)
.enter(|| {
span!(
tokio_trace::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!(
tokio_trace::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!(
tokio_trace::Level::TRACE,
"conn",
peer_addr = "8.8.8.8",
port = 18230
);
peer2.enter(|| {
debug!("connected");
});
Expand Down
10 changes: 5 additions & 5 deletions tokio-trace/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
//! # #[macro_use] extern crate tokio_trace;
//! # fn main() {
//! # let n = 1;
//! span!("my loop").enter(|| {
//! span!(tokio_trace::Level::TRACE, "my loop").enter(|| {
//! for i in 0..n {
//! # let _ = i;
//! // ...
Expand All @@ -73,7 +73,7 @@
//! # let n = 1u64;
//! for i in 0..n {
//! # let _ = i;
//! span!("my loop", iteration = i).enter(|| {
//! span!(tokio_trace::Level::TRACE, "my loop", iteration = i).enter(|| {
//! // ...
//! })
//! }
Expand Down Expand Up @@ -155,8 +155,8 @@
//! # #[macro_use]
//! # extern crate tokio_trace;
//! # fn main() {
//! // Construct a new span named "my span".
//! let mut span = span!("my span");
//! // Construct a new span named "my span" with trace log level.
//! let mut span = span!(tokio_trace::Level::TRACE, "my span");
//! span.enter(|| {
//! // Any trace events in this closure or code called by it will occur within
//! // the span.
Expand Down Expand Up @@ -196,7 +196,7 @@
//! pub fn shave_the_yak(yak: &mut Yak) {
//! // Create a new span for this invocation of `shave_the_yak`, annotated
//! // with the yak being shaved as a *field* on the span.
//! span!("shave_the_yak", yak = field::debug(&yak)).enter(|| {
//! span!(tokio_trace::Level::TRACE, "shave_the_yak", yak = field::debug(&yak)).enter(|| {
//! // Since the span is annotated with the yak, it is part of the context
//! // for everything happening inside the span. Therefore, we don't need
//! // to add it to the message for this event, as the `log` crate does.
Expand Down
Loading

0 comments on commit 89ffd06

Please sign in to comment.