Skip to content

Instantly share code, notes, and snippets.

@khionu
Last active October 6, 2020 16:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save khionu/8c9e68e34afa4990a4e53e64b79a6e70 to your computer and use it in GitHub Desktop.
Save khionu/8c9e68e34afa4990a4e53e64b79a6e70 to your computer and use it in GitHub Desktop.
Rust module for being agnostic between the Log and Tracing crates
# 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"]
#[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