alto_logger/
options.rs

1/*! Configuration for various loggers
2
3* [`StyleConfig`](enum.StyleConfig.html) allows you to choose which line-formating you want.
4* [`ColorConfig`](struct.ColorConfig.html) allows you to choose colors per element of the terminal logger.
5* [`TimeConfig`](enum.TimeConfig.html) allows you to choose which timestamp format to use.
6
7An example:
8```rust
9# use alto_logger::{Options, options::*};
10let opts = Options::default()
11    .with_style(StyleConfig::SingleLine)    // use a single-line output
12    .with_time(TimeConfig::relative_now())  // use a timestamp relative to 'now'
13    .with_color(ColorConfig::only_levels()); // only color the levels
14```
15*/
16
17mod color;
18mod style;
19mod time;
20
21#[doc(inline)]
22pub use self::time::TimeConfig;
23#[doc(inline)]
24pub use color::ColorConfig;
25#[doc(inline)]
26pub use style::StyleConfig;
27
28#[non_exhaustive]
29#[derive(Default, Clone, Debug)]
30/// Configuration for the logger
31pub struct Options {
32    /// The style configuration
33    pub style: StyleConfig,
34    /// The color configuration
35    pub color: ColorConfig,
36    /// The time configuration
37    pub time: TimeConfig,
38}
39
40impl Options {
41    /// Use this `StyleConfig` with these `Options`
42    pub const fn with_style(mut self, style: StyleConfig) -> Self {
43        self.style = style;
44        self
45    }
46
47    /// Use this `ColorConfig` with these `Options`
48    pub const fn with_color(mut self, color: ColorConfig) -> Self {
49        self.color = color;
50        self
51    }
52
53    /// Use this `TimeConfig` with these `Options`
54    // NOTE this cannot be const until const dtors are stablized (the 'String' may be dropped)
55    pub fn with_time(mut self, time: TimeConfig) -> Self {
56        self.time = time;
57        self
58    }
59}
60
61impl From<TimeConfig> for Options {
62    fn from(conf: TimeConfig) -> Self {
63        Self::default().with_time(conf)
64    }
65}
66
67impl From<ColorConfig> for Options {
68    fn from(conf: ColorConfig) -> Self {
69        Self::default().with_color(conf)
70    }
71}
72
73impl From<StyleConfig> for Options {
74    fn from(conf: StyleConfig) -> Self {
75        Self::default().with_style(conf)
76    }
77}