1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
use std::str::FromStr;

mod logger;
mod output;
mod sink;

pub use self::logger::{ContextWriter, Logger};
pub use self::sink::LogSink;
pub use bytes::Bytes;
pub use log::{debug, error, info, trace, warn, Level, LevelFilter};

/// One of the possible log formats.
#[derive(Clone, Copy)]
pub enum Format {
  /// Outputs each log entry as a JSON object separated by a newline.
  Json,
  /// Outputs each log entry separated by a newline.
  Plain,
  /// Outputs each log entry separated by a newline, in color.
  Color,
  /// Outputs each log entry separated by a newline, in color with icons.
  Modern,
}

// Implements `FromStr` to parse lowercase `Format` names.
impl FromStr for Format {
  type Err = ();

  fn from_str(s: &str) -> Result<Format, Self::Err> {
    match s.as_ref() {
      "json" => Ok(Format::Json),
      "plain" => Ok(Format::Plain),
      "color" => Ok(Format::Color),
      "modern" => Ok(Format::Modern),
      _ => Err(()),
    }
  }
}