Debian Codegraph @

third_party/rust/cubeb-core/src/log.rs

raw
1 // Copyright © 2017-2018 Mozilla Foundation
2 //
3 // This program is made available under an ISC-style license. See the
4 // accompanying file LICENSE for details.
5
6 use ffi;
7
8 /// Level (verbosity) of logging for a particular cubeb context.
9 #[derive(PartialEq, Eq, Clone, Debug, Copy, PartialOrd, Ord)]
10 pub enum LogLevel {
11 /// Logging disabled
12 Disabled,
13 /// Logging lifetime operation (creation/destruction).
14 Normal,
15 /// Verbose logging of callbacks, can have performance implications.
16 Verbose,
17 }
18
19 impl From<ffi::cubeb_log_level> for LogLevel {
20 fn from(x: ffi::cubeb_log_level) -> Self {
21 use LogLevel::*;
22 match x {
23 ffi::CUBEB_LOG_NORMAL => Normal,
24 ffi::CUBEB_LOG_VERBOSE => Verbose,
25 _ => Disabled,
26 }
27 }
28 }
29
30 pub fn log_enabled() -> bool {
31 unsafe { ffi::cubeb_log_get_level() != LogLevel::Disabled as _ }
32 }
33
34 #[cfg(test)]
35 mod tests {
36 use super::*;
37
38 #[test]
39 fn test_logging_disabled_by_default() {
40 assert!(!log_enabled());
41 }
42 }