Some checks failed
gitea/Frida-android-native/pipeline/head There was a failure building this commit
49 lines
1.3 KiB
Rust
49 lines
1.3 KiB
Rust
use crossbeam_channel::unbounded;
|
|
use crossbeam_channel::{ Sender, Receiver };
|
|
|
|
static bnd: (Sender<Vec<u8>>, Receiver<Vec<u8>>) = unbounded::<Vec<u8>>();
|
|
|
|
pub fn fetch_logs() -> Vec<u8> {
|
|
if let Ok(bytes) = bnd.1.recv() {
|
|
return bytes;
|
|
}
|
|
Vec::new()
|
|
}
|
|
|
|
pub fn push_log(data: Vec<u8>) {
|
|
bnd.0.send(data);
|
|
}
|
|
|
|
#[derive(Debug, Clone, PartialEq, Eq, Default)]
|
|
pub struct SimpleLogger {}
|
|
|
|
impl log::Log for SimpleLogger {
|
|
fn enabled(&self, metadata: &log::Metadata) -> bool {
|
|
metadata.level() <= log::Level::Trace
|
|
}
|
|
|
|
fn log(&self, record: &log::Record) {
|
|
if self.enabled(record.metadata()) {
|
|
let current_crate_name = env!("CARGO_CRATE_NAME");
|
|
if record.module_path().unwrap_or("").starts_with(current_crate_name) {
|
|
self.do_log(record);
|
|
}
|
|
}
|
|
}
|
|
|
|
fn flush(&self) {}
|
|
}
|
|
|
|
impl SimpleLogger {
|
|
fn do_log(&self, record: &log::Record) {
|
|
let timestamp: chrono::DateTime<chrono::Local> = chrono::Local::now();
|
|
let msg = format!(
|
|
"[{} {:<5} {}] - {}",
|
|
timestamp.format("%Y-%m-%d %H:%M:%S"),
|
|
record.level(),
|
|
record.module_path().unwrap_or(""),
|
|
record.args()
|
|
);
|
|
push_log(msg.as_bytes().to_vec());
|
|
}
|
|
} |