-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added logg crate -- will implement later
- Loading branch information
1 parent
ad89c1a
commit 5dec457
Showing
4 changed files
with
184 additions
and
36 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,199 @@ | ||
// #[cfg(feature = "tracing")] | ||
// use tracing::Level; | ||
// | ||
// #[cfg(feature = "logging")] | ||
// use ansi_term::Colour; | ||
|
||
/// Logs an error message. | ||
#[macro_export] | ||
macro_rules! info { | ||
macro_rules! error { | ||
($($arg:tt)*) => {{ | ||
#[cfg(feature = "logging")] | ||
println!("{} {}", $crate::color::info_prefix(), format!($($arg)*)); | ||
#[cfg(feature = "tracing")] | ||
tracing::info!($($arg)*); | ||
tracing::event!(Level::ERROR, $($arg)*); | ||
|
||
#[cfg(feature = "logging")] | ||
println!("{}", ansi_term::Colour::Red.paint(format!($($arg)*))); | ||
|
||
#[cfg(not(any(feature = "logging", feature = "tracing")))] | ||
let _ = format!($($arg)*); // No-op | ||
}}; | ||
} | ||
|
||
/// Logs a warning message. | ||
#[macro_export] | ||
macro_rules! warn { | ||
($($arg:tt)*) => {{ | ||
#[cfg(feature = "logging")] | ||
println!("{} {}", $crate::color::warn_prefix(), format!($($arg)*)); | ||
#[cfg(feature = "tracing")] | ||
tracing::warn!($($arg)*); | ||
tracing::event!(Level::WARN, $($arg)*); | ||
|
||
#[cfg(feature = "logging")] | ||
println!("{}", ansi_term::Colour::Yellow.paint(format!($($arg)*))); | ||
|
||
#[cfg(not(any(feature = "logging", feature = "tracing")))] | ||
let _ = format!($($arg)*); // No-op | ||
}}; | ||
} | ||
|
||
/// Logs an info message. | ||
#[macro_export] | ||
macro_rules! error { | ||
macro_rules! info { | ||
($($arg:tt)*) => {{ | ||
#[cfg(feature = "logging")] | ||
println!("{} {}", $crate::color::error_prefix(), format!($($arg)*)); | ||
#[cfg(feature = "tracing")] | ||
tracing::error!($($arg)*); | ||
tracing::event!(Level::INFO, $($arg)*); | ||
|
||
#[cfg(feature = "logging")] | ||
println!("{}", ansi_term::Colour::Green.paint(format!($($arg)*))); | ||
|
||
#[cfg(not(any(feature = "logging", feature = "tracing")))] | ||
let _ = format!($($arg)*); // No-op | ||
}}; | ||
} | ||
|
||
/// Logs a debug message. | ||
#[macro_export] | ||
macro_rules! debug { | ||
($($arg:tt)*) => {{ | ||
#[cfg(feature = "logging")] | ||
println!("{} {}", $crate::color::debug_prefix(), format!($($arg)*)); | ||
#[cfg(feature = "tracing")] | ||
tracing::debug!($($arg)*); | ||
}}; | ||
} | ||
|
||
pub mod color { | ||
#[cfg(feature = "logging")] | ||
pub fn info_prefix() -> String { | ||
ansi_term::Colour::Green.paint("[INFO]").to_string() | ||
} | ||
tracing::event!(Level::DEBUG, $($arg)*); | ||
|
||
#[cfg(feature = "logging")] | ||
pub fn warn_prefix() -> String { | ||
ansi_term::Colour::Yellow.paint("[WARN]").to_string() | ||
} | ||
|
||
#[cfg(feature = "logging")] | ||
pub fn error_prefix() -> String { | ||
ansi_term::Colour::Red.paint("[ERROR]").to_string() | ||
} | ||
#[cfg(feature = "logging")] | ||
println!("{}", ansi_term::Colour::Blue.paint(format!($($arg)*))); | ||
|
||
#[cfg(feature = "logging")] | ||
pub fn debug_prefix() -> String { | ||
ansi_term::Colour::Blue.paint("[DEBUG]").to_string() | ||
} | ||
#[cfg(not(any(feature = "logging", feature = "tracing")))] | ||
let _ = format!($($arg)*); // No-op | ||
}}; | ||
} | ||
|
||
// #[cfg(feature = "logging")] | ||
// use ansi_term::Colour; | ||
// | ||
// #[cfg(feature = "tracing")] | ||
// use tracing; | ||
// | ||
// /// Logs an informational message. | ||
// pub fn info(message: &str) { | ||
// #[cfg(feature = "tracing")] | ||
// { | ||
// tracing::info!("{}", message); | ||
// } | ||
// | ||
// #[cfg(feature = "logging")] | ||
// { | ||
// println!("{} {}", Colour::Green.paint("[INFO]"), message); | ||
// } | ||
// } | ||
// | ||
// /// Logs a warning message. | ||
// pub fn warn(message: &str) { | ||
// #[cfg(feature = "tracing")] | ||
// { | ||
// tracing::warn!("{}", message); | ||
// } | ||
// | ||
// #[cfg(feature = "logging")] | ||
// { | ||
// println!("{} {}", Colour::Yellow.paint("[WARN]"), message); | ||
// } | ||
// } | ||
// | ||
// /// Logs an error message. | ||
// pub fn error(message: &str) { | ||
// #[cfg(feature = "tracing")] | ||
// { | ||
// tracing::error!("{}", message); | ||
// } | ||
// | ||
// #[cfg(feature = "logging")] | ||
// { | ||
// println!("{} {}", Colour::Red.paint("[ERROR]"), message); | ||
// } | ||
// } | ||
// | ||
// /// Logs a debug message. | ||
// pub fn debug(message: &str) { | ||
// #[cfg(feature = "tracing")] | ||
// { | ||
// tracing::debug!("{}", message); | ||
// } | ||
// | ||
// #[cfg(feature = "logging")] | ||
// { | ||
// println!("{} {}", Colour::Blue.paint("[DEBUG]"), message); | ||
// } | ||
// } | ||
// | ||
// // #[macro_export] | ||
// // macro_rules! info { | ||
// // ($($arg:tt)*) => {{ | ||
// // #[cfg(feature = "logging")] | ||
// // println!("{} {}", $crate::color::info_prefix(), format!($($arg)*)); | ||
// // #[cfg(feature = "tracing")] | ||
// // tracing::info!($($arg)*); | ||
// // }}; | ||
// // } | ||
// // | ||
// // #[macro_export] | ||
// // macro_rules! warn { | ||
// // ($($arg:tt)*) => {{ | ||
// // #[cfg(feature = "logging")] | ||
// // println!("{} {}", $crate::color::warn_prefix(), format!($($arg)*)); | ||
// // #[cfg(feature = "tracing")] | ||
// // tracing::warn!($($arg)*); | ||
// // }}; | ||
// // } | ||
// // | ||
// // // #[macro_export] | ||
// // // macro_rules! error { | ||
// // // ($($arg:tt)*) => {{ | ||
// // // #[cfg(feature = "logging")] | ||
// // // println!("{} {}", $crate::color::error_prefix(), format!($($arg)*)); | ||
// // // #[cfg(feature = "tracing")] | ||
// // // tracing::error!($($arg)*); | ||
// // // }}; | ||
// // // } | ||
// // | ||
// // #[macro_export] | ||
// // macro_rules! error { | ||
// // ($($arg:tt)*) => { | ||
// // { | ||
// // #[cfg(feature = "tracing")] | ||
// // { | ||
// // tracing::error!($($arg)*); | ||
// // } | ||
// // #[cfg(feature = "logging")] | ||
// // { | ||
// // println!("\x1b[31m[ERROR]\x1b[0m {}", format!($($arg)*)); | ||
// // } | ||
// // } | ||
// // }; | ||
// // } | ||
// // | ||
// // #[macro_export] | ||
// // macro_rules! debug { | ||
// // ($($arg:tt)*) => {{ | ||
// // #[cfg(feature = "logging")] | ||
// // println!("{} {}", $crate::color::debug_prefix(), format!($($arg)*)); | ||
// // #[cfg(feature = "tracing")] | ||
// // tracing::debug!($($arg)*); | ||
// // }}; | ||
// // } | ||
// | ||
// pub mod color { | ||
// #[cfg(feature = "logging")] | ||
// pub fn info_prefix() -> String { | ||
// ansi_term::Colour::Green.paint("[INFO]").to_string() | ||
// } | ||
// | ||
// #[cfg(feature = "logging")] | ||
// pub fn warn_prefix() -> String { | ||
// ansi_term::Colour::Yellow.paint("[WARN]").to_string() | ||
// } | ||
// | ||
// #[cfg(feature = "logging")] | ||
// pub fn error_prefix() -> String { | ||
// ansi_term::Colour::Red.paint("[ERROR]").to_string() | ||
// } | ||
// | ||
// #[cfg(feature = "logging")] | ||
// pub fn debug_prefix() -> String { | ||
// ansi_term::Colour::Blue.paint("[DEBUG]").to_string() |