diff --git a/examples/logging.rs b/examples/logging.rs index 54d2cf5..bd1e00c 100644 --- a/examples/logging.rs +++ b/examples/logging.rs @@ -5,8 +5,8 @@ extern crate scribe; pub fn main() { - error!("There was an error!"); - warn!("Danger Will Robinson, danger!"); - info!("Jason is awesome."); debug!("This seemed to work alright."); + info!("Jason is awesome."); + warn!("Danger Will Robinson, danger!"); + error!("There was an error!"); } diff --git a/src/macros.rs b/src/macros.rs index 17ee702..071cfac 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -1,3 +1,15 @@ +#[doc(hidden)] +#[macro_export] +macro_rules! generate_panic +{ + ($($arg: tt)+) => + ({ + use std::fmt; + + panic!(fmt::format(format_args!($($arg)+))); + }) +} + #[doc(hidden)] #[macro_export] macro_rules! log @@ -44,50 +56,44 @@ macro_rules! log macro_rules! error { ($($arg: tt)*) => - { - { - use scribe::LogLevel; + ({ + use scribe::LogLevel; - log!(LogLevel::ERROR, $($arg)*); - } - } + + log!(LogLevel::ERROR, $($arg)*); + generate_panic!($($arg)*); + }) } #[macro_export] macro_rules! warn { ($($arg: tt)*) => - { - { - use scribe::LogLevel; + ({ + use scribe::LogLevel; - log!(LogLevel::WARN, $($arg)*); - } - } + log!(LogLevel::WARN, $($arg)*); + }) } #[macro_export] macro_rules! info { ($($arg: tt)*) => - { - { - use scribe::LogLevel; + ({ + use scribe::LogLevel; - log!(LogLevel::INFO, $($arg)*); - } - } + log!(LogLevel::INFO, $($arg)*); + }) } #[macro_export] macro_rules! debug { ($($arg: tt)*) => - { - { - use scribe::LogLevel; + ({ + use scribe::LogLevel; - log!(LogLevel::DEBUG, $($arg)*); - } - } + log!(LogLevel::DEBUG, $($arg)*); + }) }