add logging to test suite
This commit is contained in:
parent
bf2809393a
commit
17df08297c
7 changed files with 172 additions and 8 deletions
70
Cargo.lock
generated
70
Cargo.lock
generated
|
@ -95,6 +95,17 @@ dependencies = [
|
|||
"url",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "atty"
|
||||
version = "0.2.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
|
||||
dependencies = [
|
||||
"hermit-abi",
|
||||
"libc",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "autocfg"
|
||||
version = "1.1.0"
|
||||
|
@ -164,6 +175,16 @@ version = "3.11.1"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "572f695136211188308f16ad2ca5c851a712c464060ae6974944458eb83880ba"
|
||||
|
||||
[[package]]
|
||||
name = "byte-unit"
|
||||
version = "4.0.17"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "581ad4b3d627b0c09a0ccb2912148f839acaca0b93cf54cbe42b6c674e86079c"
|
||||
dependencies = [
|
||||
"serde",
|
||||
"utf8-width",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bytemuck"
|
||||
version = "1.12.2"
|
||||
|
@ -299,6 +320,17 @@ version = "1.1.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3d7b894f5411737b7867f4827955924d7c254fc9f4d91a6aad6b097804b1018b"
|
||||
|
||||
[[package]]
|
||||
name = "colored"
|
||||
version = "1.9.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f4ffc801dacf156c5854b9df4f425a626539c3a6ef7893cc0c5084a23f0b6c59"
|
||||
dependencies = [
|
||||
"atty",
|
||||
"lazy_static",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "combine"
|
||||
version = "4.6.6"
|
||||
|
@ -607,6 +639,16 @@ dependencies = [
|
|||
"instant",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "fern"
|
||||
version = "0.6.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3bdd7b0849075e79ee9a1836df22c717d1eba30451796fdc631b04565dd11e2a"
|
||||
dependencies = [
|
||||
"colored",
|
||||
"log",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "field-offset"
|
||||
version = "0.3.4"
|
||||
|
@ -1352,6 +1394,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"serde",
|
||||
"value-bag",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -2918,6 +2962,21 @@ dependencies = [
|
|||
"tauri-utils",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tauri-plugin-log"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/tauri-apps/tauri-plugin-log#b58475bbc410fa78eb69276c62d0b64c91c07914"
|
||||
dependencies = [
|
||||
"byte-unit",
|
||||
"fern",
|
||||
"log",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"serde_repr",
|
||||
"tauri",
|
||||
"time",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tauri-runtime"
|
||||
version = "0.12.0"
|
||||
|
@ -2983,6 +3042,7 @@ dependencies = [
|
|||
"serde_json",
|
||||
"tauri",
|
||||
"tauri-build",
|
||||
"tauri-plugin-log",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -3320,6 +3380,16 @@ version = "0.1.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d"
|
||||
|
||||
[[package]]
|
||||
name = "value-bag"
|
||||
version = "1.0.0-alpha.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2209b78d1249f7e6f3293657c9779fe31ced465df091bbd433a1cf88e916ec55"
|
||||
dependencies = [
|
||||
"ctor",
|
||||
"version_check",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "vcpkg"
|
||||
version = "0.2.15"
|
||||
|
|
|
@ -13,7 +13,7 @@ wasm-bindgen-futures = "0.4.32"
|
|||
futures-util = "0.3.25"
|
||||
serde = { version = "1.0.147", features = ["derive"] }
|
||||
wasm-logger = "0.2.0"
|
||||
log = "0.4.17"
|
||||
log = { version = "0.4.17", features = ["serde"] }
|
||||
|
||||
[features]
|
||||
ci = []
|
||||
|
|
|
@ -17,6 +17,7 @@ tauri-build = { version = "1.2", features = [] }
|
|||
serde_json = "1.0"
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
tauri = { version = "1.2", features = ["api-all"] }
|
||||
tauri-plugin-log = {git = "https://github.com/tauri-apps/tauri-plugin-log", features = ["colored"] }
|
||||
|
||||
[features]
|
||||
# by default Tauri runs in production mode
|
||||
|
|
|
@ -4,8 +4,8 @@
|
|||
)]
|
||||
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
|
||||
use tauri::{Manager, State, api::notification::Notification};
|
||||
use tauri::{Manager, State};
|
||||
use tauri_plugin_log::{LogTarget, LoggerBuilder};
|
||||
|
||||
struct Received(AtomicBool);
|
||||
// Learn more about Tauri commands at https://tauri.app/v1/guides/features/command
|
||||
|
@ -21,7 +21,20 @@ fn exit_with_error(e: &str) -> bool {
|
|||
}
|
||||
|
||||
fn main() {
|
||||
let log_plugin = {
|
||||
let targets = [
|
||||
LogTarget::LogDir,
|
||||
#[cfg(debug_assertions)]
|
||||
LogTarget::Stdout,
|
||||
#[cfg(debug_assertions)]
|
||||
LogTarget::Webview,
|
||||
];
|
||||
|
||||
LoggerBuilder::new().targets(targets).build()
|
||||
};
|
||||
|
||||
tauri::Builder::default()
|
||||
.plugin(log_plugin)
|
||||
.invoke_handler(tauri::generate_handler![verify_receive, exit_with_error])
|
||||
.setup(|app| {
|
||||
app.manage(Received(AtomicBool::new(false)));
|
||||
|
|
|
@ -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
Reference in a new issue