[tauri-plugin-log] How to Obtain app_handle to Emit Events in Custom Log Targets? #13509
-
pub fn run() {
let __builder = tauri::Builder::default()
.plugin(
tauri_plugin_log::Builder::new()
.clear_targets()
.target(tauri_plugin_log::Target::new(
tauri_plugin_log::TargetKind::Dispatch(
fern::Dispatch::new()
.chain(fern::Output::call(|record| {
println!("{}", record.args());
// emit
// app.emit("mylog://log", "msg ..");
})),
),
))
.build(),
)
.setup(|app| {
Ok(())
})
.invoke_handler(tauri::generate_handler![])
.run(tauri::generate_context!())
.expect("error while running tauri application");
} |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
If there isn't a better way to obtain app_handle, here's an idea I have for solving this problem:
But I feel this might be a bit overly complicated. https://github.com/mcitem/plugins-workspace/commit/bf2519efdc14a62974619773c7feca9d29124740 |
Beta Was this translation helpful? Give feedback.
-
You can register the plugin inside the setup hook as well instead of on the Builder. There you'll have easy access to an AppHandle. That registers the logger a tiny bit later though so some plugin's logs mayyy get missed? |
Beta Was this translation helpful? Give feedback.
You can register the plugin inside the setup hook as well instead of on the Builder. There you'll have easy access to an AppHandle. That registers the logger a tiny bit later though so some plugin's logs mayyy get missed?