Skip to content

Commit

Permalink
Prevent lint warnings if internal-logs features is not enabled. (#2196)
Browse files Browse the repository at this point in the history
  • Loading branch information
lalitb authored Oct 13, 2024
1 parent c3687d4 commit bacb3da
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions opentelemetry/src/global/internal_logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,20 @@ macro_rules! otel_info {
{
tracing::info!( name: $name, target: env!("CARGO_PKG_NAME"), "");
}
#[cfg(not(feature = "internal-logs"))]
{
let _ = $name; // Compiler will optimize this out as it's unused.
}
};
(name: $name:expr, $($key:ident = $value:expr),+ $(,)?) => {
#[cfg(feature = "internal-logs")]
{
tracing::info!(name: $name, target: env!("CARGO_PKG_NAME"), $($key = $value),+, "");
}
#[cfg(not(feature = "internal-logs"))]
{
let _ = ($name, $($value),+); // Compiler will optimize this out as it's unused.
}
};
}

Expand All @@ -50,12 +58,20 @@ macro_rules! otel_warn {
{
tracing::warn!(name: $name, target: env!("CARGO_PKG_NAME"), "");
}
#[cfg(not(feature = "internal-logs"))]
{
let _ = $name; // Compiler will optimize this out as it's unused.
}
};
(name: $name:expr, $($key:ident = $value:expr),+ $(,)?) => {
#[cfg(feature = "internal-logs")]
{
tracing::warn!(name: $name, target: env!("CARGO_PKG_NAME"), $($key = $value),+, "");
}
#[cfg(not(feature = "internal-logs"))]
{
let _ = ($name, $($value),+); // Compiler will optimize this out as it's unused.
}
};
}

Expand All @@ -77,12 +93,20 @@ macro_rules! otel_debug {
{
tracing::debug!(name: $name, target: env!("CARGO_PKG_NAME"),"");
}
#[cfg(not(feature = "internal-logs"))]
{
let _ = $name; // Compiler will optimize this out as it's unused.
}
};
(name: $name:expr, $($key:ident = $value:expr),+ $(,)?) => {
#[cfg(feature = "internal-logs")]
{
tracing::debug!(name: $name, target: env!("CARGO_PKG_NAME"), $($key = $value),+, "");
}
#[cfg(not(feature = "internal-logs"))]
{
let _ = ($name, $($value),+); // Compiler will optimize this out as it's unused.
}
};
}

Expand All @@ -104,11 +128,19 @@ macro_rules! otel_error {
{
tracing::error!(name: $name, target: env!("CARGO_PKG_NAME"), "");
}
#[cfg(not(feature = "internal-logs"))]
{
let _ = $name; // Compiler will optimize this out as it's unused.
}
};
(name: $name:expr, $($key:ident = $value:expr),+ $(,)?) => {
#[cfg(feature = "internal-logs")]
{
tracing::error!(name: $name, target: env!("CARGO_PKG_NAME"), $($key = $value),+, "");
}
#[cfg(not(feature = "internal-logs"))]
{
let _ = ($name, $($value),+); // Compiler will optimize this out as it's unused.
}
};
}

0 comments on commit bacb3da

Please sign in to comment.