-
Notifications
You must be signed in to change notification settings - Fork 750
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
subscriber: add more ergonomic subscriber configuration APIs #660
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
499d979
subscriber: add less-verbose configuration APIs
hawkw ca6354c
even nicer easymode
hawkw f6ea40c
wip
hawkw c3f1bcb
wip on event format apis
hawkw 5dae043
update examples, add docs
hawkw c6720a4
fix non-compile-y example
hawkw c383c8a
hopefully make errors play nicer with `?`
hawkw 9959e95
fixup bad doctest examples
hawkw ed2d128
nice-ify examples
hawkw a4507eb
add examples of overriding formatters
hawkw 88ef120
fix unused import in examples
hawkw 8ec6842
make custom field format example a little nicer
hawkw 6ddbdbe
use fully-qualified name
hawkw 665e88d
use easymode in the readme
hawkw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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,29 @@ | ||
#![deny(rust_2018_idioms)] | ||
use tracing_subscriber; | ||
#[path = "fmt/yak_shave.rs"] | ||
mod yak_shave; | ||
|
||
fn main() { | ||
use tracing_subscriber::fmt; | ||
|
||
// Configure a custom event formatter | ||
let format = fmt::format() | ||
.compact() // use an abbreviated format for logging spans | ||
.with_level(false) // don't include levels in formatted output | ||
.with_target(false); // don't include targets | ||
|
||
// Create a `fmt` subscriber that uses our custom event format, and set it | ||
// as the default. | ||
tracing_subscriber::fmt().event_format(format).init(); | ||
|
||
// Shave some yaks! | ||
let number_of_yaks = 3; | ||
// this creates a new event, outside of any spans. | ||
tracing::info!(number_of_yaks, "preparing to shave yaks"); | ||
|
||
let number_shaved = yak_shave::shave_all(number_of_yaks); | ||
tracing::info!( | ||
all_yaks_shaved = number_shaved == number_of_yaks, | ||
"yak shaving completed." | ||
); | ||
} |
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,53 @@ | ||
//! This example demonstrates overriding the way `tracing-subscriber`'s | ||
//! `FmtSubscriber` formats fields on spans and events, using a closure. | ||
//! | ||
//! We'll create a custom format that prints key-value pairs separated by | ||
//! colons rather than equals signs, and separates fields with commas. | ||
//! | ||
//! For an event like | ||
//! ```rust | ||
//! tracing::info!(hello = "world", answer = 42); | ||
//! ``` | ||
//! | ||
//! the default formatter will format the fields like this: | ||
//! ```not_rust | ||
//! hello="world" answer=42 | ||
//! ``` | ||
//! while our custom formatter will output | ||
//! ```not_rust | ||
//! hello: "world", answer: 42 | ||
//! ``` | ||
#![deny(rust_2018_idioms)] | ||
use tracing_subscriber; | ||
|
||
#[path = "fmt/yak_shave.rs"] | ||
mod yak_shave; | ||
|
||
fn main() { | ||
use tracing_subscriber::{fmt::format, prelude::*}; | ||
|
||
// Format fields using the provided closure. | ||
let format = format::debug_fn(|writer, field, value| { | ||
// We'll format the field name and value separated with a colon. | ||
write!(writer, "{}: {:?}", field, value) | ||
}) | ||
// Separate each field with a comma. | ||
// This method is provided by an extension trait in the | ||
// `tracing-subscriber` prelude. | ||
.delimited(", "); | ||
hawkw marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// Create a `fmt` subscriber that uses our custom event format, and set it | ||
// as the default. | ||
tracing_subscriber::fmt().fmt_fields(format).init(); | ||
|
||
// Shave some yaks! | ||
let number_of_yaks = 3; | ||
// this creates a new event, outside of any spans. | ||
tracing::info!(number_of_yaks, "preparing to shave yaks"); | ||
|
||
let number_shaved = yak_shave::shave_all(number_of_yaks); | ||
tracing::info!( | ||
all_yaks_shaved = number_shaved == number_of_yaks, | ||
"yak shaving completed." | ||
); | ||
} |
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
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
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wish there was a way to replace this expr with something like
tracing_subscriber::fmt()
, aka some sort of conversion fn for a fmt builder to a registry + layer