Last active
October 6, 2020 16:08
-
-
Save khionu/8c9e68e34afa4990a4e53e64b79a6e70 to your computer and use it in GitHub Desktop.
Rust module for being agnostic between the Log and Tracing crates
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
# Need both of these. Make sure to add the current version | |
[dependencies.log] | |
version = "..." | |
optional = true | |
[dependencies.tracing] | |
version = "..." | |
optional = true | |
# Add these for configuring | |
[features] | |
default = ["use-tracing"] | |
# or default = ["use-log"] | |
use-log = ["log"] | |
use-tracing = ["tracing"] |
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
#[macro_export] | |
macro_rules! __error__ { | |
($($tokens:tt)*) => { | |
#[cfg(feature = "use-log")] | |
{ | |
log::error!($($tokens)*) | |
} | |
#[cfg(feature = "use-tracing")] | |
{ | |
tracing::error!($($tokens)*) | |
} | |
}; | |
} | |
#[macro_export] | |
macro_rules! __warn__ { | |
($($tokens:tt)*) => { | |
#[cfg(feature = "use-log")] | |
{ | |
log::warn!($($tokens)*) | |
} | |
#[cfg(feature = "use-tracing")] | |
{ | |
tracing::warn!($($tokens)*) | |
} | |
}; | |
} | |
#[macro_export] | |
macro_rules! __info__ { | |
($($tokens:tt)*) => { | |
#[cfg(feature = "use-log")] | |
{ | |
log::info!($($tokens)*) | |
} | |
#[cfg(feature = "use-tracing")] | |
{ | |
tracing::info!($($tokens)*) | |
} | |
}; | |
} | |
#[macro_export] | |
macro_rules! __debug__ { | |
($($tokens:tt)*) => { | |
#[cfg(feature = "use-log")] | |
{ | |
log::debug!($($tokens)*) | |
} | |
#[cfg(feature = "use-tracing")] | |
{ | |
tracing::debug!($($tokens)*) | |
} | |
}; | |
} | |
#[macro_export] | |
macro_rules! __trace__ { | |
($($tokens:tt)*) => { | |
#[cfg(feature = "use-log")] | |
{ | |
log::trace!($($tokens)*) | |
} | |
#[cfg(feature = "use-tracing")] | |
{ | |
tracing::trace!($($tokens)*) | |
} | |
}; | |
} | |
pub use __debug__ as debug; | |
pub use __error__ as error; | |
pub use __info__ as info; | |
pub use __trace__ as trace; | |
pub use __warn__ as warn; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment