44 lines
1.1 KiB
Rust
44 lines
1.1 KiB
Rust
//! Bounded human-readable log records.
|
|
|
|
use crate::{Level, LogText};
|
|
|
|
/// Internal transport priority selected from a conventional log level.
|
|
pub enum DeliveryClass {
|
|
/// Error-level logs.
|
|
Critical,
|
|
/// Warning, info, debug, and trace logs.
|
|
BestEffort,
|
|
}
|
|
|
|
/// One bounded transport-neutral log event.
|
|
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
|
pub struct LogRecord {
|
|
level: Level,
|
|
message: LogText,
|
|
}
|
|
|
|
impl LogRecord {
|
|
/// Creates one bounded log record at the supplied level.
|
|
pub(crate) const fn new(level: Level, message: LogText) -> Self {
|
|
Self { level, message }
|
|
}
|
|
|
|
/// Conventional log level.
|
|
pub const fn level(&self) -> Level {
|
|
self.level
|
|
}
|
|
|
|
/// Fixed human-readable message.
|
|
pub const fn message(&self) -> &LogText {
|
|
&self.message
|
|
}
|
|
|
|
/// Internal transport priority.
|
|
pub const fn delivery(&self) -> DeliveryClass {
|
|
match self.level {
|
|
Level::Error => DeliveryClass::Critical,
|
|
Level::Warn | Level::Info | Level::Debug | Level::Trace => DeliveryClass::BestEffort,
|
|
}
|
|
}
|
|
}
|