evdev_rs/
logging.rs

1use evdev_sys as raw;
2
3pub enum LogPriority {
4    /// critical errors and application bugs
5    Error = raw::LIBEVDEV_LOG_ERROR as isize,
6    /// informational messages
7    Info = raw::LIBEVDEV_LOG_INFO as isize,
8    /// debug information
9    Debug = raw::LIBEVDEV_LOG_DEBUG as isize,
10}
11
12/// Define the minimum level to be printed to the log handler.
13/// Messages higher than this level are printed, others are discarded. This
14/// is a global setting and applies to any future logging messages.
15pub fn set_log_priority(priority: LogPriority) {
16    unsafe {
17        raw::libevdev_set_log_priority(priority as i32);
18    }
19}
20
21/// Return the current log priority level. Messages higher than this level
22/// are printed, others are discarded. This is a global setting.
23pub fn get_log_priority() -> LogPriority {
24    unsafe {
25        let priority = raw::libevdev_get_log_priority();
26        match priority {
27            raw::LIBEVDEV_LOG_ERROR => LogPriority::Error,
28            raw::LIBEVDEV_LOG_INFO => LogPriority::Info,
29            raw::LIBEVDEV_LOG_DEBUG => LogPriority::Debug,
30            c => panic!("unknown log priority: {}", c),
31        }
32    }
33}