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
46
47
48
49
50
51
// Buttplug Rust Source Code File - See https://buttplug.io for more info.

//

// Copyright 2016-2020 Nonpolynomial Labs LLC. All rights reserved.

//

// Licensed under the BSD 3-Clause license. See LICENSE file in the project root

// for full license information.


#[cfg(feature = "serialize-json")]
use serde::{Deserialize, Serialize};
use std::cmp::Ord;
use tracing::Level;

#[derive(Debug, PartialEq, Clone, Ord, PartialOrd, Eq)]
#[cfg_attr(feature = "serialize-json", derive(Serialize, Deserialize))]
pub enum LogLevel {
  Off = 0,
  Fatal,
  Error,
  Warn,
  Info,
  Debug,
  Trace,
}

impl From<Level> for LogLevel {
  fn from(level: Level) -> Self {
    match level {
      Level::ERROR => LogLevel::Error,
      Level::WARN => LogLevel::Warn,
      Level::INFO => LogLevel::Info,
      Level::DEBUG => LogLevel::Debug,
      Level::TRACE => LogLevel::Trace,
    }
  }
}

impl Into<Level> for LogLevel {
  fn into(self) -> Level {
    match self {
      // Rust doesn't have a Fatal level, and we never use it in code, so

      // just convert to Error.

      LogLevel::Fatal => Level::ERROR,
      LogLevel::Error => Level::ERROR,
      LogLevel::Warn => Level::WARN,
      LogLevel::Info => Level::INFO,
      LogLevel::Debug => Level::DEBUG,
      LogLevel::Trace => Level::TRACE,
      LogLevel::Off => panic!("Log messages with a log level of Off are not allowed"),
    }
  }
}