-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Replace `env_logger` with `tracing`/`tracing-subscriber`/`tracing-log` TODO: - Implement slog drain that would *properly* convert slog records into tracing events (`slog-stdlog` is fine for now, though) * fixup! Replace `env_logger` with `tracing`/`tracing-subscriber`/`tracing-log` Fix `consensus` test * fixup! fixup! Replace `env_logger` with `tracing`/`tracing-subscriber`/`tracing-log` Forget to `unwrap` the result 🙈 * fixup! fixup! Replace `env_logger` with `tracing`/`tracing-subscriber`/`tracing-log` `tracing_subscriber::fmt::init` initializes `tracing_log::LogTracer` automatically with default `tracing-subscriber` features enabled 💁♀️ * Update `DEVELOPMENT.md` documentation regarding `tracing` * Update default log level for development to make it less noisy --------- Co-authored-by: timvisee <[email protected]>
- Loading branch information
Showing
8 changed files
with
54 additions
and
120 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,55 +1,40 @@ | ||
#[cfg_attr(not(feature = "tracing-logger"), allow(unused_variables))] | ||
pub fn setup(log_level: &str) -> anyhow::Result<()> { | ||
// Use `console` and/or `tracy` features to enable both `tracing-subscriber` and the layer(s) | ||
#[cfg(feature = "tracing-subscriber")] | ||
{ | ||
use tracing_subscriber::prelude::*; | ||
|
||
let reg = tracing_subscriber::registry(); | ||
|
||
// Use `console` feature to enable both `tracing-subscriber` and `console-subscriber` | ||
#[cfg(feature = "console-subscriber")] | ||
let reg = reg.with(console_subscriber::spawn()); | ||
|
||
// Note, that `console-subscriber` requires manually enabling | ||
// `--cfg tokio_unstable` rust flags during compilation! | ||
// | ||
// Otherwise `console_subscriber::spawn` call panics! | ||
// | ||
// See https://docs.rs/tokio/latest/tokio/#unstable-features | ||
#[cfg(all(feature = "console-subscriber", not(tokio_unstable)))] | ||
eprintln!( | ||
"`console-subscriber` requires manually enabling \ | ||
`--cfg tokio_unstable` rust flags during compilation!" | ||
); | ||
|
||
// Use `tracy` feature to enable both `tracing-subscriber` and `tracing-tracy` | ||
#[cfg(feature = "tracing-tracy")] | ||
let reg = reg.with(tracing_tracy::TracyLayer::new().with_filter( | ||
tracing_subscriber::filter::filter_fn(|metadata| metadata.is_span()), | ||
)); | ||
use tracing_subscriber::prelude::*; | ||
use tracing_subscriber::{filter, fmt}; | ||
|
||
#[cfg(all(feature = "tracing-log-always", feature = "tracing-logger"))] | ||
eprintln!( | ||
"Both `tracing-log-always` and `tracing-logger` features are enabled at the same time. \ | ||
This will cause some logs to be printed twice!" | ||
); | ||
|
||
#[cfg(feature = "tracing-logger")] | ||
let reg = reg.with( | ||
tracing_subscriber::fmt::layer() | ||
.with_ansi(true) | ||
.with_span_events(tracing_subscriber::fmt::format::FmtSpan::NEW) | ||
.with_filter( | ||
tracing_subscriber::filter::EnvFilter::builder().parse_lossy(log_level), | ||
), | ||
); | ||
|
||
#[cfg(feature = "tracing-logger")] | ||
tracing_log::LogTracer::init()?; | ||
|
||
tracing::subscriber::set_global_default(reg)?; | ||
} | ||
pub fn setup(log_level: &str) -> anyhow::Result<()> { | ||
tracing_log::LogTracer::init()?; | ||
|
||
let reg = tracing_subscriber::registry().with( | ||
fmt::layer() | ||
.with_ansi(true) | ||
.with_span_events(fmt::format::FmtSpan::NEW) | ||
.with_filter(filter::EnvFilter::builder().parse_lossy(log_level)), | ||
); | ||
|
||
// Use `console` or `console-subscriber` feature to enable `console-subscriber` | ||
// | ||
// Note, that `console-subscriber` requires manually enabling | ||
// `--cfg tokio_unstable` rust flags during compilation! | ||
// | ||
// Otherwise `console_subscriber::spawn` call panics! | ||
// | ||
// See https://docs.rs/tokio/latest/tokio/#unstable-features | ||
#[cfg(all(feature = "console-subscriber", tokio_unstable))] | ||
let reg = reg.with(console_subscriber::spawn()); | ||
|
||
#[cfg(all(feature = "console-subscriber", not(tokio_unstable)))] | ||
eprintln!( | ||
"`console-subscriber` requires manually enabling \ | ||
`--cfg tokio_unstable` rust flags during compilation!" | ||
); | ||
|
||
// Use `tracy` or `tracing-tracy` feature to enable `tracing-tracy` | ||
#[cfg(feature = "tracing-tracy")] | ||
let reg = reg.with(tracing_tracy::TracyLayer::new().with_filter( | ||
tracing_subscriber::filter::filter_fn(|metadata| metadata.is_span()), | ||
)); | ||
|
||
tracing::subscriber::set_global_default(reg)?; | ||
|
||
Ok(()) | ||
} |