use ndk_sys::{android_LogPriority, log_id};
use tracing_core::Level;
#[repr(u32)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub enum Priority {
Verbose = android_LogPriority::ANDROID_LOG_VERBOSE.0,
Debug = android_LogPriority::ANDROID_LOG_DEBUG.0,
Info = android_LogPriority::ANDROID_LOG_INFO.0,
Warn = android_LogPriority::ANDROID_LOG_WARN.0,
Error = android_LogPriority::ANDROID_LOG_ERROR.0,
Fatal = android_LogPriority::ANDROID_LOG_FATAL.0,
}
#[repr(u32)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Buffer {
Default = log_id::LOG_ID_DEFAULT.0,
Main = log_id::LOG_ID_MAIN.0,
Crash = log_id::LOG_ID_CRASH.0,
Stats = log_id::LOG_ID_STATS.0,
Events = log_id::LOG_ID_EVENTS.0,
Security = log_id::LOG_ID_SECURITY.0,
System = log_id::LOG_ID_SYSTEM.0,
Kernel = log_id::LOG_ID_KERNEL.0,
Radio = log_id::LOG_ID_RADIO.0,
}
impl Priority {
pub fn as_raw(self) -> android_LogPriority {
android_LogPriority(self as u32)
}
}
impl From<Level> for Priority {
fn from(l: Level) -> Self {
match l {
Level::TRACE => Priority::Verbose,
Level::DEBUG => Priority::Debug,
Level::INFO => Priority::Info,
Level::WARN => Priority::Warn,
Level::ERROR => Priority::Error,
}
}
}
impl From<Priority> for Level {
fn from(p: Priority) -> Self {
match p {
Priority::Verbose => Level::TRACE,
Priority::Debug => Level::DEBUG,
Priority::Info => Level::INFO,
Priority::Warn => Level::WARN,
Priority::Error | Priority::Fatal => Level::ERROR,
}
}
}
impl Buffer {
pub(crate) fn as_raw(self) -> log_id {
log_id(self as u32)
}
}
impl Default for Buffer {
fn default() -> Self {
Self::Default
}
}