Error logging now generates a panic.

This means that the error macro must be called last in the example.
This commit is contained in:
Jason Travis Smith 2016-01-28 14:15:21 -05:00
parent d1e6e8f4fe
commit d6a6f5107c
2 changed files with 33 additions and 27 deletions

View File

@ -5,8 +5,8 @@ extern crate scribe;
pub fn main() pub fn main()
{ {
error!("There was an error!");
warn!("Danger Will Robinson, danger!");
info!("Jason is awesome.");
debug!("This seemed to work alright."); debug!("This seemed to work alright.");
info!("Jason is awesome.");
warn!("Danger Will Robinson, danger!");
error!("There was an error!");
} }

View File

@ -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)] #[doc(hidden)]
#[macro_export] #[macro_export]
macro_rules! log macro_rules! log
@ -44,50 +56,44 @@ macro_rules! log
macro_rules! error macro_rules! error
{ {
($($arg: tt)*) => ($($arg: tt)*) =>
{ ({
{ use scribe::LogLevel;
use scribe::LogLevel;
log!(LogLevel::ERROR, $($arg)*);
} log!(LogLevel::ERROR, $($arg)*);
} generate_panic!($($arg)*);
})
} }
#[macro_export] #[macro_export]
macro_rules! warn macro_rules! warn
{ {
($($arg: tt)*) => ($($arg: tt)*) =>
{ ({
{ use scribe::LogLevel;
use scribe::LogLevel;
log!(LogLevel::WARN, $($arg)*); log!(LogLevel::WARN, $($arg)*);
} })
}
} }
#[macro_export] #[macro_export]
macro_rules! info macro_rules! info
{ {
($($arg: tt)*) => ($($arg: tt)*) =>
{ ({
{ use scribe::LogLevel;
use scribe::LogLevel;
log!(LogLevel::INFO, $($arg)*); log!(LogLevel::INFO, $($arg)*);
} })
}
} }
#[macro_export] #[macro_export]
macro_rules! debug macro_rules! debug
{ {
($($arg: tt)*) => ($($arg: tt)*) =>
{ ({
{ use scribe::LogLevel;
use scribe::LogLevel;
log!(LogLevel::DEBUG, $($arg)*); log!(LogLevel::DEBUG, $($arg)*);
} })
}
} }