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
39
40
41
42
43
44
45
use std::fmt;

/// Log levels to be used with a [`Logger`](struct.Level.html).
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub enum Level {
  Error,
  Warn,
  Info,
  Verbose,
  Debug,
  Trace,
}

impl fmt::Display for Level {
  fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
    use self::Level::*;
    match self {
      &Error => write!(f, "error"),
      &Warn => write!(f, "warn"),
      &Info => write!(f, "info"),
      &Verbose => write!(f, "verbose"),
      &Debug => write!(f, "debug"),
      &Trace => write!(f, "trace"),
    }
  }
}

impl<S> From<S> for Level
where
  S: AsRef<str>,
{
  fn from(string: S) -> Self {
    use self::Level::*;
    let s = string.as_ref();
    match s {
      "error" => Error,
      "warn" => Warn,
      "info" => Info,
      "verbose" => Verbose,
      "debug" => Debug,
      "trace" => Trace,
      _ => panic!("{} is not a valid level", s),
    }
  }
}