-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support completing spans as results with ok_lvl and err_lvl
- Loading branch information
Showing
9 changed files
with
313 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
use std::time::Duration; | ||
|
||
#[derive(thiserror::Error, Debug)] | ||
#[error("invalid number {n}")] | ||
struct Error { | ||
n: i32, | ||
} | ||
|
||
// The `guard` control parameter binds an `emit::Span` that you can use | ||
// to manually complete your span, adding extra properties if needed. | ||
// | ||
// If you don't complete the span manually then it will complete on its | ||
// own when it falls out of scope. | ||
#[emit::span( | ||
ok_lvl: emit::Level::Info, | ||
err_lvl: emit::Level::Error, | ||
"Running an example", | ||
i, | ||
)] | ||
fn example(i: i32) -> Result<(), Error> { | ||
let r = i + 1; | ||
|
||
if r == 4 { | ||
Err(Error { n: r }) | ||
} else { | ||
Ok(()) | ||
} | ||
} | ||
|
||
fn main() { | ||
let rt = emit::setup().emit_to(emit_term::stdout()).init(); | ||
|
||
let _ = example(1); | ||
let _ = example(3); | ||
|
||
rt.blocking_flush(Duration::from_secs(5)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.