paranoid_android/
logging.rs1use ndk_sys::{android_LogPriority, log_id};
2use tracing_core::Level;
3
4#[repr(u32)]
5#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
6pub enum Priority {
7 Verbose = android_LogPriority::ANDROID_LOG_VERBOSE.0,
8 Debug = android_LogPriority::ANDROID_LOG_DEBUG.0,
9 Info = android_LogPriority::ANDROID_LOG_INFO.0,
10 Warn = android_LogPriority::ANDROID_LOG_WARN.0,
11 Error = android_LogPriority::ANDROID_LOG_ERROR.0,
12 Fatal = android_LogPriority::ANDROID_LOG_FATAL.0,
13}
14
15#[repr(u32)]
17#[derive(Debug, Clone, Copy, PartialEq, Eq)]
18pub enum Buffer {
19 Default = log_id::LOG_ID_DEFAULT.0,
21
22 Main = log_id::LOG_ID_MAIN.0,
26
27 Crash = log_id::LOG_ID_CRASH.0,
29 Stats = log_id::LOG_ID_STATS.0,
31 Events = log_id::LOG_ID_EVENTS.0,
33 Security = log_id::LOG_ID_SECURITY.0,
35 System = log_id::LOG_ID_SYSTEM.0,
37 Kernel = log_id::LOG_ID_KERNEL.0,
39 Radio = log_id::LOG_ID_RADIO.0,
41}
42
43impl Priority {
44 pub fn as_raw(self) -> android_LogPriority {
45 android_LogPriority(self as u32)
46 }
47}
48
49impl From<Level> for Priority {
50 fn from(l: Level) -> Self {
51 match l {
52 Level::TRACE => Priority::Verbose,
53 Level::DEBUG => Priority::Debug,
54 Level::INFO => Priority::Info,
55 Level::WARN => Priority::Warn,
56 Level::ERROR => Priority::Error,
57 }
58 }
59}
60
61impl From<Priority> for Level {
62 fn from(p: Priority) -> Self {
63 match p {
64 Priority::Verbose => Level::TRACE,
65 Priority::Debug => Level::DEBUG,
66 Priority::Info => Level::INFO,
67 Priority::Warn => Level::WARN,
68 Priority::Error | Priority::Fatal => Level::ERROR,
69 }
70 }
71}
72
73impl Buffer {
74 pub(crate) fn as_raw(self) -> log_id {
75 log_id(self as u32)
76 }
77}
78
79impl Default for Buffer {
80 fn default() -> Self {
81 Self::Default
82 }
83}