.
//
//!
//! # Log Entry Level
//!
//! This module provides the enum containing the possible log entry levels.
//! The order in which they are listed within the enum, enables logging at that level
//! and at all higher levels.
//!
//! The levels in descending order are:
//!
//! - SEVERE (highest level)
//! - WARNING
//! - INFO
//! - CONFIG
//! - FINE
//! - FINER
//! - FINEST (lowest level)
//!
//! In addition there is a level **OFF** that can be used to turn off logging.
use ::{, str::};
use ::{,};
///
/// Log entry level setting.
///
/// Default level: INFO.
///
// #[allow(unused)]
#[derive(,,,,,,)]
pub enum Level {
///
/// ALL is a special level that can be used to turn on logging
/// for all levels.
///
ALL,
///
/// FINEST indicates a highly detailed tracing message.
///
FINEST,
///
/// FINER indicates a fairly detailed tracing message.
/// Suggest logging calls for entering, returning,
/// or `Error`s, such as returned via `Result`, are traced at
/// this level.
///
FINER,
///
/// FINE is a message level providing tracing information.
///
/// All of FINE, FINER, and FINEST are intended for relatively
/// detailed tracing. The exact meaning of the three levels will
/// vary between subsystems, but in general, FINEST should be
/// used for the most voluminous detailed output, FINER for somewhat
/// less detailed output, and FINE for the lowest volume (and most
/// important) messages.
///
/// In general the FINE level should be used for information that
/// will be broadly interesting to developers who do not have a
/// specialized interest in the specific subsystem.
///
/// FINE messages might include things like minor (recoverable)
/// failures. Issues indicating potential performance problems are
/// also worth logging as FINE.
///
FINE,
///
/// CONFIG is a message level for static configuration messages.
///
/// CONFIG messages are intended to provide a variety of static
/// configuration information, to assist in debugging problems
/// that may be associated with particular configurations.
///
/// For example, a CONFIG message might include the CPU type, the
/// graphics depth, the GUI look-and-feel, etc.
///
CONFIG,
///
/// INFO is a message level for informational messages.
///
/// Typically INFO messages will be written to the console or its
/// equivalent. So the INFO level should only be used for reasonably
/// significant messages that will make sense to end users and system
/// administrators.
///
/// \[default level]
///
#[default]
INFO,
///
/// WARNING is a message level indicating a potential problem.
///
/// In general WARNING messages should describe events that will be
/// of interest to end users or system managers, or which indicate
/// potential problems.
///
WARNING,
///
/// SEVERE is a message level indicating a serious failure.
///
/// In general SEVERE messages should describe events that are of
/// considerable importance and which will prevent normal program
/// execution. They should be reasonably intelligible to end users
/// and to system administrators.
///
SEVERE,
///
/// OFF is a special level that can be used to turn off logging.
///
OFF,
}
impl Level {
///
/// Converts a level to its string version.
///
pub const fn as_str(&self) -> &'static str {
match self {
::ALL => "ALL",
::FINEST => "FINEST",
::FINER => "FINER",
::FINE => "FINE",
::CONFIG => "CONFIG",
::INFO => "INFO",
::WARNING => "WARNING",
::SEVERE => "SEVERE",
::OFF => "OFF",
}
}
}
impl ::for Level {
fn fmt(&selff: &mut ::<_>) -> :: {
selfas_str()fmt()
}
}
#[allow()]
#[derive()]
pub struct LevelError {
msg:
}
impl for Level {
type Err =;
fn from_str(s: &str) -> <SelfSelf::> {
match{
"ALL" => Ok(::ALL),
"FINEST" => Ok(::FINEST),
"FINER" => Ok(::FINER),
"FINE" => Ok(::FINE),
"CONFIG" => Ok(::CONFIG),
"INFO" => Ok(::INFO),
"WARNING" => Ok(::WARNING),
"SEVERE" => Ok(::SEVERE),
"OFF" => Ok(::OFF),
_ => Err({
: format!("Unknown Level: {s}"),
}),
}
}
}
#[cfg()]
mod tests {
use super::*;
#[test]
fn compare_levels() {
let= ::();
let= ::FINE;
println!("\n|{log_level}|\n");
assert!(<);
}
#[test]
fn check_conversions() {
forin ::() {
let=as_str();
let= ::()unwrap();
assert_eq!(,);
}
assert!(::("DEBUG")is_err());
}
}