-
-
Notifications
You must be signed in to change notification settings - Fork 267
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
Update tracing-subscriber and use tracing-tree when testing #586
Merged
Merged
Changes from all commits
Commits
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,17 @@ | ||
use std::{io, str}; | ||
pub use tracing; | ||
pub use tracing_subscriber; | ||
|
||
pub fn init() -> tracing::dispatcher::DefaultGuard { | ||
tracing::subscriber::set_default( | ||
tracing_subscriber::fmt() | ||
.with_max_level(tracing::Level::TRACE) | ||
.with_span_events(tracing_subscriber::fmt::format::FmtSpan::CLOSE) | ||
.with_writer(PrintlnWriter { _p: () }) | ||
.finish(), | ||
) | ||
} | ||
|
||
struct PrintlnWriter { | ||
_p: (), | ||
} | ||
use tracing_subscriber::layer::SubscriberExt; | ||
use tracing_subscriber::util::SubscriberInitExt; | ||
|
||
impl tracing_subscriber::fmt::MakeWriter for PrintlnWriter { | ||
type Writer = PrintlnWriter; | ||
fn make_writer(&self) -> Self::Writer { | ||
PrintlnWriter { _p: () } | ||
} | ||
} | ||
|
||
impl io::Write for PrintlnWriter { | ||
fn write(&mut self, buf: &[u8]) -> io::Result<usize> { | ||
let s = str::from_utf8(buf).map_err(|e| io::Error::new(io::ErrorKind::InvalidInput, e))?; | ||
println!("{}", s); | ||
Ok(s.len()) | ||
} | ||
|
||
fn write_fmt(&mut self, fmt: std::fmt::Arguments<'_>) -> io::Result<()> { | ||
println!("{}", fmt); | ||
Ok(()) | ||
} | ||
pub fn init() -> tracing::dispatcher::DefaultGuard { | ||
let use_colors = atty::is(atty::Stream::Stdout); | ||
let layer = tracing_tree::HierarchicalLayer::default() | ||
.with_writer(tracing_subscriber::fmt::writer::TestWriter::default()) | ||
.with_indent_lines(true) | ||
.with_ansi(use_colors) | ||
.with_targets(true) | ||
.with_indent_amount(2); | ||
|
||
fn flush(&mut self) -> io::Result<()> { | ||
Ok(()) | ||
} | ||
tracing_subscriber::registry().with(layer).set_default() | ||
} |
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.
take it or leave it: perhaps we want to add
in particular, adding thread names will give us a nice way to know which test the events were logged from, since the thread's name defaults to the name of the test.
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 added it but I'm not sure this is useful: I only ever look at logs running a single test, not many of them.
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.
It's a bit verbose as you can see.
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.
hmm, we could remove it --- i suppose that since libtest is capturing the logs now, they'll also be printed out per-test. the only reason to consider having thread names here is if we have tests that spawn multiple threads and they give names to those threads...and we only have one test that spawns threads (https://github.com/hyperium/h2/search?q=thread%3A%3Aspawn).
i'm fine with removing the thread-name configuration, then!