Skip to content

Commit

Permalink
clean up structured logging example
Browse files Browse the repository at this point in the history
  • Loading branch information
KodrAus committed Feb 19, 2024
1 parent 646e9ab commit 2b220bf
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,22 @@ If you enable the `kv` feature, you can associate structured data with your log
use log::{info, trace, warn};

pub fn shave_the_yak(yak: &mut Yak) {
trace!(target = "yak_events", yak:serde = yak; "Commencing yak shaving");
// `yak:serde` will capture `yak` using its `serde::Serialize` impl
//
// You could also use `:?` for `Debug`, or `:%` for `Display`. For a
// full list, see the `log` crate documentation
trace!(target = "yak_events", yak:serde; "Commencing yak shaving");

loop {
match find_a_razor() {
Ok(razor) => {
info!(razor = razor; "Razor located");
info!(razor; "Razor located");
yak.shave(razor);
break;
}
Err(err) => {
warn!(err:err; "Unable to locate a razor, retrying");
Err(e) => {
// `e:err` will capture `e` using its `std::error::Error` impl
warn!(e:err; "Unable to locate a razor, retrying");
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,17 +102,17 @@
//! use log::{info, warn};
//!
//! pub fn shave_the_yak(yak: &mut Yak) {
//! info!(target: "yak_events", yak:serde = yak; "Commencing yak shaving");
//! info!(target: "yak_events", yak:serde; "Commencing yak shaving");
//!
//! loop {
//! match find_a_razor() {
//! Ok(razor) => {
//! info!(razor = razor; "Razor located");
//! info!(razor; "Razor located");
//! yak.shave(razor);
//! break;
//! }
//! Err(err) => {
//! warn!(err:err; "Unable to locate a razor, retrying");
//! Err(e) => {
//! warn!(e:err; "Unable to locate a razor, retrying");
//! }
//! }
//! }
Expand Down

0 comments on commit 2b220bf

Please sign in to comment.