mod android;
mod null;
mod stderr;
#[repr(i32)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum LogLevel {
Verbose = 2,
Debug = 3,
Info = 4,
Warn = 5,
Error = 6,
Fatal = 7,
}
pub type LogPriority = LogLevel;
#[repr(u8)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum LogBackend {
Android = 0,
Stderr = 1,
Null = 2,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Logger {
backend: LogBackend,
}
impl Default for Logger {
fn default() -> Self {
#[cfg(target_os = "android")]
{
Self::new(LogBackend::Android)
}
#[cfg(not(target_os = "android"))]
{
Self::new(LogBackend::Stderr)
}
}
}
impl Logger {
pub fn new(backend: LogBackend) -> Self {
Self { backend }
}
pub fn log(&self, level: LogLevel, tag: &str, msg: &str) {
match self.backend {
LogBackend::Android => android::log(level, tag, msg),
LogBackend::Stderr => stderr::log(level, tag, msg),
LogBackend::Null => null::log(level, tag, msg),
}
}
}
pub fn log(level: LogLevel, tag: &str, msg: &str) {
#[cfg(target_os = "android")]
{
android::log(level, tag, msg);
}
#[cfg(not(target_os = "android"))]
{
stderr::log(level, tag, msg);
}
}
pub fn log_write(level: LogLevel, tag: &str, msg: &str) {
log(level, tag, msg);
}
#[macro_export]
macro_rules! alog_verbose {
($tag:expr, $($arg:tt)*) => {
$crate::log::log($crate::log::LogLevel::Verbose, $tag, &format!($($arg)*))
};
($tag:expr) => {
$crate::log::log($crate::log::LogLevel::Verbose, $tag, "")
};
}
#[macro_export]
macro_rules! alog_debug {
($tag:expr, $($arg:tt)*) => {
$crate::log::log($crate::log::LogLevel::Debug, $tag, &format!($($arg)*))
};
($tag:expr) => {
$crate::log::log($crate::log::LogLevel::Debug, $tag, "")
};
}
#[macro_export]
macro_rules! alog_info {
($tag:expr, $($arg:tt)*) => {
$crate::log::log($crate::log::LogLevel::Info, $tag, &format!($($arg)*))
};
($tag:expr) => {
$crate::log::log($crate::log::LogLevel::Info, $tag, "")
};
}
#[macro_export]
macro_rules! alog_warn {
($tag:expr, $($arg:tt)*) => {
$crate::log::log($crate::log::LogLevel::Warn, $tag, &format!($($arg)*))
};
($tag:expr) => {
$crate::log::log($crate::log::LogLevel::Warn, $tag, "")
};
}
#[macro_export]
macro_rules! alog_error {
($tag:expr, $($arg:tt)*) => {
$crate::log::log($crate::log::LogLevel::Error, $tag, &format!($($arg)*))
};
($tag:expr) => {
$crate::log::log($crate::log::LogLevel::Error, $tag, "")
};
}
#[macro_export]
macro_rules! alog_fatal {
($tag:expr, $($arg:tt)*) => {
$crate::log::log($crate::log::LogLevel::Fatal, $tag, &format!($($arg)*))
};
($tag:expr) => {
$crate::log::log($crate::log::LogLevel::Fatal, $tag, "")
};
}
#[macro_export]
macro_rules! log_verbose {
($tag:expr, $($arg:tt)*) => {
$crate::log::log($crate::log::LogLevel::Verbose, $tag, &format!($($arg)*))
};
($tag:expr) => {
$crate::log::log($crate::log::LogLevel::Verbose, $tag, "")
};
}
#[macro_export]
macro_rules! log_debug {
($tag:expr, $($arg:tt)*) => {
$crate::log::log($crate::log::LogLevel::Debug, $tag, &format!($($arg)*))
};
($tag:expr) => {
$crate::log::log($crate::log::LogLevel::Debug, $tag, "")
};
}
#[macro_export]
macro_rules! log_info {
($tag:expr, $($arg:tt)*) => {
$crate::log::log($crate::log::LogLevel::Info, $tag, &format!($($arg)*))
};
($tag:expr) => {
$crate::log::log($crate::log::LogLevel::Info, $tag, "")
};
}
#[macro_export]
macro_rules! log_warn {
($tag:expr, $($arg:tt)*) => {
$crate::log::log($crate::log::LogLevel::Warn, $tag, &format!($($arg)*))
};
($tag:expr) => {
$crate::log::log($crate::log::LogLevel::Warn, $tag, "")
};
}
#[macro_export]
macro_rules! log_error {
($tag:expr, $($arg:tt)*) => {
$crate::log::log($crate::log::LogLevel::Error, $tag, &format!($($arg)*))
};
($tag:expr) => {
$crate::log::log($crate::log::LogLevel::Error, $tag, "")
};
}
#[macro_export]
macro_rules! log_fatal {
($tag:expr, $($arg:tt)*) => {
$crate::log::log($crate::log::LogLevel::Fatal, $tag, &format!($($arg)*))
};
($tag:expr) => {
$crate::log::log($crate::log::LogLevel::Fatal, $tag, "")
};
}