add logging to test suite
This commit is contained in:
parent
bf2809393a
commit
17df08297c
7 changed files with 172 additions and 8 deletions
|
@ -1,16 +1,19 @@
|
|||
mod app;
|
||||
mod clipboard;
|
||||
mod event;
|
||||
mod window;
|
||||
mod dialog;
|
||||
mod event;
|
||||
mod notification;
|
||||
mod os;
|
||||
mod tauri_log;
|
||||
mod window;
|
||||
|
||||
extern crate console_error_panic_hook;
|
||||
use log::LevelFilter;
|
||||
use std::future::Future;
|
||||
use std::panic;
|
||||
use sycamore::prelude::*;
|
||||
use sycamore::suspense::Suspense;
|
||||
use tauri_log::TauriLogger;
|
||||
|
||||
#[cfg(feature = "ci")]
|
||||
async fn exit_with_error(e: String) {
|
||||
|
@ -127,8 +130,12 @@ pub async fn Terminate<'a, G: Html>(cx: Scope<'a>) -> View<G> {
|
|||
}
|
||||
}
|
||||
|
||||
static LOGGER: TauriLogger = TauriLogger;
|
||||
|
||||
fn main() {
|
||||
wasm_logger::init(wasm_logger::Config::default());
|
||||
log::set_logger(&LOGGER)
|
||||
.map(|()| log::set_max_level(LevelFilter::Trace))
|
||||
.unwrap();
|
||||
|
||||
panic::set_hook(Box::new(|info| {
|
||||
console_error_panic_hook::hook(info);
|
||||
|
@ -163,7 +170,7 @@ fn main() {
|
|||
Test(name="notification::is_permission_granted",test=notification::is_permission_granted())
|
||||
Test(name="notification::request_permission",test=notification::request_permission())
|
||||
InteractiveTest(name="notification::show_notification",test=notification::show_notification())
|
||||
|
||||
|
||||
// Test(name="window::WebviewWindow::new",test=window::create_window())
|
||||
|
||||
Terminate
|
||||
|
|
|
@ -19,7 +19,7 @@ pub async fn platform() -> anyhow::Result<()> {
|
|||
pub async fn tempdir() -> anyhow::Result<()> {
|
||||
let tempdir = os::tempdir().await?;
|
||||
|
||||
log::debug!("{:?}", tempdir);
|
||||
log::info!("{:?}", tempdir);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
73
examples/test/src/tauri_log.rs
Normal file
73
examples/test/src/tauri_log.rs
Normal file
|
@ -0,0 +1,73 @@
|
|||
use log::{Metadata, Record};
|
||||
use serde::Serialize;
|
||||
use tauri_sys::tauri;
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
struct LogArgs {
|
||||
level: Level,
|
||||
message: String,
|
||||
file: Option<String>,
|
||||
line: Option<u32>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
enum Level {
|
||||
Trace,
|
||||
Debug,
|
||||
Info,
|
||||
Warn,
|
||||
Error,
|
||||
}
|
||||
|
||||
impl From<log::Level> for Level {
|
||||
fn from(l: log::Level) -> Self {
|
||||
match l {
|
||||
log::Level::Error => Level::Error,
|
||||
log::Level::Warn => Level::Warn,
|
||||
log::Level::Info => Level::Info,
|
||||
log::Level::Debug => Level::Debug,
|
||||
log::Level::Trace => Level::Trace,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Serialize for Level {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: serde::Serializer,
|
||||
{
|
||||
serializer.serialize_u8(match self {
|
||||
Level::Trace => 1,
|
||||
Level::Debug => 2,
|
||||
Level::Info => 3,
|
||||
Level::Warn => 4,
|
||||
Level::Error => 5,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
pub struct TauriLogger;
|
||||
impl log::Log for TauriLogger {
|
||||
fn enabled(&self, metadata: &Metadata) -> bool {
|
||||
metadata.level() <= log::Level::Trace
|
||||
}
|
||||
|
||||
fn log(&self, record: &Record) {
|
||||
if self.enabled(record.metadata()) {
|
||||
let args = LogArgs {
|
||||
level: record.level().into(),
|
||||
message: format!("{}", record.args()),
|
||||
file: record.file().map(ToString::to_string),
|
||||
line: record.line(),
|
||||
};
|
||||
|
||||
wasm_bindgen_futures::spawn_local(async move {
|
||||
tauri::invoke::<_, ()>("plugin:log|log", &args)
|
||||
.await
|
||||
.unwrap();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
fn flush(&self) {}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue