timber_rust/logger/level.rs
1use std::borrow::Cow;
2
3/// Severity levels for log categorization.
4///
5/// Variants represent a standard range of log priorities. This enum implements
6/// [`From<Level>`] for [`Cow<'static, str>`], allowing it to satisfy the string-based
7/// level requirements of the [`Loggable`][`crate::logger::Loggable`] trait without unnecessary allocations.
8/// Represents the severity level of a log message.
9#[derive(Debug, Clone, Copy, PartialEq, Eq)]
10pub enum Level {
11 /// Designates fine-grained informational events that are most useful to debug an application.
12 Debug,
13 /// Designates informational messages that highlight the progress of the application
14 /// at coarse-grained level.
15 Info,
16 /// Designates a successful operation or a positive milestone in the application flow.
17 Success,
18 /// Designates potentially harmful situations that should be monitored but do not
19 /// stop the application.
20 Warn,
21 /// Designates error events that might still allow the application to continue running.
22 Error,
23 /// Designates severe error events that could lead the application to abort or
24 /// lose critical functionality.
25 Critical,
26 /// Designates very severe error events that will presumably lead the application
27 /// to terminate immediately.
28 Fatal,
29}
30
31impl From<Level> for Cow<'static, str> {
32 /// Converts a [`Level`] variant into its static string representation.
33 ///
34 /// This uses [`Cow::Borrowed`] to ensure zero-allocation during
35 /// the conversion process.
36 fn from(level: Level) -> Self {
37 match level {
38 Level::Debug => Cow::Borrowed("DEBUG"),
39 Level::Info => Cow::Borrowed("INFO"),
40 Level::Success => Cow::Borrowed("SUCCESS"),
41 Level::Warn => Cow::Borrowed("WARN"),
42 Level::Error => Cow::Borrowed("ERROR"),
43 Level::Critical => Cow::Borrowed("CRITICAL"),
44 Level::Fatal => Cow::Borrowed("FATAL"),
45 }
46 }
47}