Skip to content
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

Allow disabling logging feature #1190

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion tracing/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ async-await = []

alloc = ["tracing-core/alloc"]
std = ["tracing-core/std", "alloc"]
log-always = ["log"]
logging = ["log"]
log-always = ["logging"]
attributes = ["tracing-attributes"]

[[bench]]
Expand Down
6 changes: 3 additions & 3 deletions tracing/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -910,7 +910,7 @@
#[macro_use]
extern crate cfg_if;

#[cfg(feature = "log")]
#[cfg(feature = "logging")]
#[doc(hidden)]
pub use log;

Expand Down Expand Up @@ -1049,13 +1049,13 @@ pub mod __macro_support {
}

#[inline]
#[cfg(feature = "log")]
#[cfg(feature = "logging")]
pub fn disabled_span(&self) -> crate::Span {
crate::Span::new_disabled(self.meta)
}

#[inline]
#[cfg(not(feature = "log"))]
#[cfg(not(feature = "logging"))]
pub fn disabled_span(&self) -> crate::Span {
crate::Span::none()
}
Expand Down
16 changes: 8 additions & 8 deletions tracing/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2149,7 +2149,7 @@ macro_rules! fieldset {

}

#[cfg(feature = "log")]
#[cfg(feature = "logging")]
#[doc(hidden)]
#[macro_export]
macro_rules! level_to_log {
Expand All @@ -2172,14 +2172,14 @@ macro_rules! __tracing_stringify {
};
}

#[cfg(not(feature = "log"))]
#[cfg(not(feature = "logging"))]
#[doc(hidden)]
#[macro_export]
macro_rules! __tracing_log {
(target: $target:expr, $level:expr, $($field:tt)+ ) => {};
}

#[cfg(feature = "log")]
#[cfg(feature = "logging")]
#[doc(hidden)]
#[macro_export]
macro_rules! __mk_format_string {
Expand Down Expand Up @@ -2227,7 +2227,7 @@ macro_rules! __mk_format_string {
}
}

#[cfg(feature = "log")]
#[cfg(feature = "logging")]
#[doc(hidden)]
#[macro_export]
macro_rules! __mk_format_args {
Expand Down Expand Up @@ -2294,7 +2294,7 @@ macro_rules! __mk_format_args {
};
}

#[cfg(feature = "log")]
#[cfg(feature = "logging")]
#[doc(hidden)]
#[macro_export]
macro_rules! __tracing_log {
Expand Down Expand Up @@ -2322,7 +2322,7 @@ macro_rules! __tracing_log {
};
}

#[cfg(not(feature = "log"))]
#[cfg(not(feature = "logging"))]
#[doc(hidden)]
#[macro_export]
macro_rules! if_log_enabled {
Expand All @@ -2337,7 +2337,7 @@ macro_rules! if_log_enabled {
};
}

#[cfg(all(feature = "log", not(feature = "log-always")))]
#[cfg(all(feature = "logging", not(feature = "log-always")))]
#[doc(hidden)]
#[macro_export]
macro_rules! if_log_enabled {
Expand All @@ -2356,7 +2356,7 @@ macro_rules! if_log_enabled {
};
}

#[cfg(all(feature = "log", feature = "log-always"))]
#[cfg(all(feature = "logging", feature = "log-always"))]
#[doc(hidden)]
#[macro_export]
macro_rules! if_log_enabled {
Expand Down
14 changes: 7 additions & 7 deletions tracing/src/span.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,10 +383,10 @@ pub struct Entered<'a> {
}

/// `log` target for all span lifecycle (creation/enter/exit/close) records.
#[cfg(feature = "log")]
#[cfg(feature = "logging")]
const LIFECYCLE_LOG_TARGET: &str = "tracing::span";
/// `log` target for span activity (enter/exit) records.
#[cfg(feature = "log")]
#[cfg(feature = "logging")]
const ACTIVITY_LOG_TARGET: &str = "tracing::span::active";

// ===== impl Span =====
Expand Down Expand Up @@ -1030,7 +1030,7 @@ impl Span {
self.meta
}

#[cfg(feature = "log")]
#[cfg(feature = "logging")]
#[inline]
fn log(&self, target: &str, level: log::Level, message: fmt::Arguments<'_>) {
if let Some(ref meta) = self.meta {
Expand Down Expand Up @@ -1259,10 +1259,10 @@ impl<'a> Drop for Entered<'a> {
}
}

#[cfg(feature = "log")]
#[cfg(feature = "logging")]
struct FmtValues<'a>(&'a Record<'a>);

#[cfg(feature = "log")]
#[cfg(feature = "logging")]
impl<'a> fmt::Display for FmtValues<'a> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let mut res = Ok(());
Expand All @@ -1275,10 +1275,10 @@ impl<'a> fmt::Display for FmtValues<'a> {
}
}

#[cfg(feature = "log")]
#[cfg(feature = "logging")]
struct FmtAttrs<'a>(&'a Attributes<'a>);

#[cfg(feature = "log")]
#[cfg(feature = "logging")]
impl<'a> fmt::Display for FmtAttrs<'a> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let mut res = Ok(());
Expand Down