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
// Copyright © 2017-2018 Mozilla Foundation
//
// This program is made available under an ISC-style license.  See the
// accompanying file LICENSE for details.

use ffi;

/// Level (verbosity) of logging for a particular cubeb context.
#[derive(PartialEq, Eq, Clone, Debug, Copy, PartialOrd, Ord)]
pub enum LogLevel {
    /// Logging disabled
    Disabled,
    /// Logging lifetime operation (creation/destruction).
    Normal,
    /// Verbose logging of callbacks, can have performance implications.
    Verbose,
}

impl From<ffi::cubeb_log_level> for LogLevel {
    fn from(x: ffi::cubeb_log_level) -> Self {
        use LogLevel::*;
        match x {
            ffi::CUBEB_LOG_NORMAL => Normal,
            ffi::CUBEB_LOG_VERBOSE => Verbose,
            _ => Disabled,
        }
    }
}

pub fn log_enabled() -> bool {
    unsafe { ffi::g_cubeb_log_level != LogLevel::Disabled as _ }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_logging_disabled_by_default() {
        assert!(!log_enabled());
    }
}