Skip to content

Commit

Permalink
feat(trace): add internal tracing macro module
Browse files Browse the repository at this point in the history
Introduce several macros that act as wrappers around the `tracing`
module's macros to allow for more concise syntax for conditional
compilation of `tracing` macro calls. As `tracing` is unstable,
the new `trace` module will facilitate transitioning `tracing`
to an optional feature, as outlined in hyperium#2874 and hyperium#3326.

BREAKING CHANGES: Integration of macros requires the replacement of
uses of `trace` macros.
  • Loading branch information
RamziA961 committed Sep 27, 2023
1 parent a2f89d0 commit 6bc791e
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ pub use crate::error::{Error, Result};
#[macro_use]
mod cfg;
#[macro_use]
mod trace;
#[macro_use]
mod common;
pub mod body;
mod error;
Expand Down
107 changes: 107 additions & 0 deletions src/trace.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
#![allow(unused_macros)]

macro_rules! debug {
($($arg:tt)+) => {
#[cfg(feature = "tracing")]
{
println!($($arg)+);
tracing::debug!($($arg)+);
}
}
}

macro_rules! debug_span {
($($arg:tt)*) => {
#[cfg(feature = "tracing")]
{
let span = tracing::debug_span!($($arg)+);
let _ = span.enter();
}
}
}

macro_rules! error {
($($arg:tt)*) => {
#[cfg(feature = "tracing")]
{
tracing::error!($($arg)+);
}
}
}

macro_rules! error_span {
($($arg:tt)*) => {
#[cfg(feature = "tracing")]
{
let span = tracing::error_span!($($arg)+);
let _ = span.enter();
}
}
}

macro_rules! info {
($($arg:tt)*) => {
#[cfg(feature = "tracing")]
{
tracing::info!($($arg)+);
}
}
}

macro_rules! info_span {
($($arg:tt)*) => {
#[cfg(feature = "tracing")]
{
let span = tracing::info_span!($($arg)+);
let _ = span.enter();
}
}
}

macro_rules! trace {
($($arg:tt)*) => {
#[cfg(feature = "tracing")]
{
tracing::trace!($($arg)+);
}
}
}

macro_rules! trace_span {
($($arg:tt)*) => {
#[cfg(feature = "tracing")]
{
let span = tracing::trace_span!($($arg)+);
let _ = span.enter();
}
}
}

macro_rules! span {
($($arg:tt)*) => {
#[cfg(feature = "tracing")]
{
let span = tracing::span!($($arg)+);
let _ = span.enter();
}
}
}

macro_rules! warn {
($($arg:tt)*) => {
#[cfg(feature = "tracing")]
{
tracing::warn!($($arg)+);
}
}
}

macro_rules! warn_span {
($($arg:tt)*) => {
#[cfg(feature = "tracing")]
{
let span = tracing::warn_span!($($arg)+);
let _ = span.enter();
}
}
}

0 comments on commit 6bc791e

Please sign in to comment.