forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#136392 - jieyouxu:wrap-tracing, r=onur-ozkan
bootstrap: add wrapper macros for `feature = "tracing"`-gated `tracing` macros Follow-up to rust-lang#136091 (comment). - Add wrapper macros for `error!`, `warn!`, `info!`, `debug!` and `trace!`, which `cfg(feature = "tracing")`-gates the underlying `tracing` macros. They expand to nothing if `"tracing"` feature is not enabled. - This is not done for `span!` or `event!` because they can return span guards, and you can't really wrap that. - This is also not possible for `tracing::instrument` attribute proc-macro unless you use another attribute proc-macro to wrap that. It's not *great*, because `tracing::instrument` and `tracing::{span,event}` can't be wrapped this way. Can test locally with: ```bash $ BOOTSTRAP_TRACING=bootstrap=TRACE ./x check src/bootstrap/ ``` r? ``@onur-ozkan`` (or reroll)
- Loading branch information
Showing
4 changed files
with
99 additions
and
51 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
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,49 @@ | ||
//! Wrapper macros for `tracing` macros to avoid having to write `cfg(feature = "tracing")`-gated | ||
//! `debug!`/`trace!` everytime, e.g. | ||
//! | ||
//! ```rust,ignore (example) | ||
//! #[cfg(feature = "tracing")] | ||
//! trace!("..."); | ||
//! ``` | ||
//! | ||
//! When `feature = "tracing"` is inactive, these macros expand to nothing. | ||
#[macro_export] | ||
macro_rules! trace { | ||
($($tokens:tt)*) => { | ||
#[cfg(feature = "tracing")] | ||
::tracing::trace!($($tokens)*) | ||
} | ||
} | ||
|
||
#[macro_export] | ||
macro_rules! debug { | ||
($($tokens:tt)*) => { | ||
#[cfg(feature = "tracing")] | ||
::tracing::debug!($($tokens)*) | ||
} | ||
} | ||
|
||
#[macro_export] | ||
macro_rules! warn { | ||
($($tokens:tt)*) => { | ||
#[cfg(feature = "tracing")] | ||
::tracing::warn!($($tokens)*) | ||
} | ||
} | ||
|
||
#[macro_export] | ||
macro_rules! info { | ||
($($tokens:tt)*) => { | ||
#[cfg(feature = "tracing")] | ||
::tracing::info!($($tokens)*) | ||
} | ||
} | ||
|
||
#[macro_export] | ||
macro_rules! error { | ||
($($tokens:tt)*) => { | ||
#[cfg(feature = "tracing")] | ||
::tracing::error!($($tokens)*) | ||
} | ||
} |