-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
166 additions
and
148 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[package] | ||
name = "vent-logging" | ||
version.workspace = true | ||
edition.workspace = true | ||
|
||
[dependencies] | ||
log = { version="0.4", features = ["std"] } | ||
colored = "2.1.0" | ||
|
||
[target.'cfg(target_family = "wasm")'.dependencies] | ||
web-sys = { version = "0.3.69", features = ["console"] } | ||
|
||
[target.'cfg(target_os = "android")'.dependencies] | ||
ndk-sys = "0.6" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
use colored::Colorize; | ||
use log::{Level, LevelFilter, Log}; | ||
|
||
/// | ||
/// Cross Platform Logger | ||
/// | ||
pub struct Logger { | ||
} | ||
|
||
impl Logger { | ||
pub fn new() { | ||
log::set_max_level(LevelFilter::Trace); | ||
log::set_boxed_logger(Box::new(Self {})).expect("failed to set boxed logger"); | ||
} | ||
} | ||
|
||
impl Log for Logger { | ||
fn enabled(&self, metadata: &log::Metadata) -> bool { | ||
true // TODO | ||
} | ||
|
||
fn log(&self, record: &log::Record) { | ||
// Default | ||
#[cfg(not(any(target_arch = "wasm32", target_os = "android")))] | ||
{ | ||
let level = match record.level() { | ||
Level::Error => format!("{:<5}", record.level().to_string().red()), | ||
Level::Warn => format!("{:<5}", record.level().to_string().yellow()), | ||
Level::Info => format!("{:<5}", record.level().to_string().cyan()), | ||
Level::Debug => format!("{:<5}", record.level().to_string().purple()), | ||
Level::Trace => format!("{:<5}", record.level().to_string().normal()), | ||
}; | ||
println!("{} {}", level, record.args()) | ||
} | ||
// Wasm | ||
#[cfg(target_family = "wasm")] | ||
{ | ||
match record.level() { | ||
Level::Error => web_sys::console::error_1(&format!("{}", record.args()).into()), | ||
Level::Warn => web_sys::console::warn_1(&format!("{}", record.args()).into()), | ||
Level::Info => web_sys::console::info_1(&format!("{}", record.args()).into()), | ||
Level::Debug => web_sys::console::debug_1(&format!("{}", record.args()).into()), | ||
Level::Trace => web_sys::console::trace_1(&format!("{}", record.args()).into()), | ||
} | ||
} | ||
// Android | ||
#[cfg(target_os = "android")] | ||
{ | ||
use std::ffi::{c_int, CStr, CString}; | ||
let prio = match record.level() { | ||
Level::Error => ndk_sys::android_LogPriority::ANDROID_LOG_ERROR, | ||
Level::Warn => ndk_sys::android_LogPriority::ANDROID_LOG_WARN, | ||
Level::Info => ndk_sys::android_LogPriority::ANDROID_LOG_INFO, | ||
Level::Debug => ndk_sys::android_LogPriority::ANDROID_LOG_DEBUG, | ||
Level::Trace => ndk_sys::android_LogPriority::ANDROID_LOG_VERBOSE, | ||
}; | ||
unsafe { | ||
ndk_sys::__android_log_write( | ||
prio.0 as c_int, | ||
CStr::from("").as_ptr(), | ||
record.args().as_ptr(), | ||
); | ||
} | ||
} | ||
} | ||
|
||
fn flush(&self) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters