use core::cmp;
use core::fmt;
-static LOG_LEVEL_NAMES: [&'static str; 6] = ["OFF", "ERROR", "WARN", "INFO", "DEBUG", "TRACE"];
+static LOG_LEVEL_NAMES: [&'static str; 5] = ["TRACE", "DEBUG", "INFO", "WARN", "ERROR"];
/// An enum representing the available verbosity levels of the logger.
#[derive(Copy, Clone, PartialEq, Eq, Debug, Hash)]
pub enum Level {
- ///Designates logger being silent
- Off,
- /// Designates very serious errors
- Error,
- /// Designates hazardous situations
- Warn,
- /// Designates useful information
- Info,
- /// Designates lower priority information
- Debug,
/// Designates very low priority, often extremely verbose, information
Trace,
+ /// Designates lower priority information
+ Debug,
+ /// Designates useful information
+ Info,
+ /// Designates hazardous situations
+ Warn,
+ /// Designates very serious errors
+ Error,
}
impl PartialOrd for Level {
let wrapper = WrapperLog::new(Arc::clone(&logger));
wrapper.call_macros();
}
+
+ #[test]
+ fn test_log_ordering() {
+ assert!(Level::Error > Level::Warn);
+ assert!(Level::Error >= Level::Warn);
+ assert!(Level::Error >= Level::Error);
+ assert!(Level::Warn > Level::Info);
+ assert!(Level::Warn >= Level::Info);
+ assert!(Level::Warn >= Level::Warn);
+ assert!(Level::Info > Level::Debug);
+ assert!(Level::Info >= Level::Debug);
+ assert!(Level::Info >= Level::Info);
+ assert!(Level::Debug > Level::Trace);
+ assert!(Level::Debug >= Level::Trace);
+ assert!(Level::Debug >= Level::Debug);
+ assert!(Level::Trace >= Level::Trace);
+
+ assert!(Level::Error <= Level::Error);
+ assert!(Level::Warn < Level::Error);
+ assert!(Level::Warn <= Level::Error);
+ assert!(Level::Warn <= Level::Warn);
+ assert!(Level::Info < Level::Warn);
+ assert!(Level::Info <= Level::Warn);
+ assert!(Level::Info <= Level::Info);
+ assert!(Level::Debug < Level::Info);
+ assert!(Level::Debug <= Level::Info);
+ assert!(Level::Debug <= Level::Debug);
+ assert!(Level::Trace < Level::Debug);
+ assert!(Level::Trace <= Level::Debug);
+ assert!(Level::Trace <= Level::Trace);
+ }
}
);
}
+/// Logs an entry at the given level.
+#[macro_export]
+macro_rules! log_given_level {
+ ($logger: expr, $lvl:expr, $($arg:tt)+) => (
+ match $lvl {
+ #[cfg(not(any(feature = "max_level_off")))]
+ $crate::util::logger::Level::Error => log_internal!($logger, $lvl, $($arg)*),
+ #[cfg(not(any(feature = "max_level_off", feature = "max_level_error")))]
+ $crate::util::logger::Level::Warn => log_internal!($logger, $lvl, $($arg)*),
+ #[cfg(not(any(feature = "max_level_off", feature = "max_level_error", feature = "max_level_warn")))]
+ $crate::util::logger::Level::Info => log_internal!($logger, $lvl, $($arg)*),
+ #[cfg(not(any(feature = "max_level_off", feature = "max_level_error", feature = "max_level_warn", feature = "max_level_info")))]
+ $crate::util::logger::Level::Debug => log_internal!($logger, $lvl, $($arg)*),
+ #[cfg(not(any(feature = "max_level_off", feature = "max_level_error", feature = "max_level_warn", feature = "max_level_info", feature = "max_level_debug")))]
+ $crate::util::logger::Level::Trace => log_internal!($logger, $lvl, $($arg)*),
+
+ #[cfg(any(feature = "max_level_off", feature = "max_level_error", feature = "max_level_warn", feature = "max_level_info", feature = "max_level_debug"))]
+ _ => {
+ // The level is disabled at compile-time
+ },
+ }
+ );
+}
+
/// Log an error.
#[macro_export]
macro_rules! log_error {
($logger: expr, $($arg:tt)*) => (
- #[cfg(not(any(feature = "max_level_off")))]
- log_internal!($logger, $crate::util::logger::Level::Error, $($arg)*);
+ log_given_level!($logger, $crate::util::logger::Level::Error, $($arg)*);
)
}
macro_rules! log_warn {
($logger: expr, $($arg:tt)*) => (
- #[cfg(not(any(feature = "max_level_off", feature = "max_level_error")))]
- log_internal!($logger, $crate::util::logger::Level::Warn, $($arg)*);
+ log_given_level!($logger, $crate::util::logger::Level::Warn, $($arg)*);
)
}
macro_rules! log_info {
($logger: expr, $($arg:tt)*) => (
- #[cfg(not(any(feature = "max_level_off", feature = "max_level_error", feature = "max_level_warn")))]
- log_internal!($logger, $crate::util::logger::Level::Info, $($arg)*);
+ log_given_level!($logger, $crate::util::logger::Level::Info, $($arg)*);
)
}
macro_rules! log_debug {
($logger: expr, $($arg:tt)*) => (
- #[cfg(not(any(feature = "max_level_off", feature = "max_level_error", feature = "max_level_warn", feature = "max_level_info")))]
- log_internal!($logger, $crate::util::logger::Level::Debug, $($arg)*);
+ log_given_level!($logger, $crate::util::logger::Level::Debug, $($arg)*);
)
}
#[macro_export]
macro_rules! log_trace {
($logger: expr, $($arg:tt)*) => (
- #[cfg(not(any(feature = "max_level_off", feature = "max_level_error", feature = "max_level_warn", feature = "max_level_info", feature = "max_level_debug")))]
- log_internal!($logger, $crate::util::logger::Level::Trace, $($arg)*);
+ log_given_level!($logger, $crate::util::logger::Level::Trace, $($arg)*);
)
}