tauri-apps / plugins-workspace

All of the official Tauri plugins in one place!
https://tauri.app
Apache License 2.0
994 stars 278 forks source link

[bug] tauri_plugin_log with TargetKind::Webview causes infinite log loop #2126

Open tdomhan opened 19 hours ago

tdomhan commented 19 hours ago

Describe the bug

When using the tauri_plugin_log plugin with the Webview target as such

        .plugin(
            tauri_plugin_log::Builder::new()
                .targets([Target::new(TargetKind::Stdout), Target::new(TargetKind::Webview)])
                .level(LevelFilter::Info)
                .build(),
        )

I get an infinite stream of

[2024-12-03][07:20:30][tauri::manager][INFO] app::emit; event="log://log"
[2024-12-03][07:20:30][tauri::manager][INFO] app::emit; event="log://log"
[2024-12-03][07:20:30][tauri::manager][INFO] app::emit; event="log://log"
[2024-12-03][07:20:30][tauri::manager][INFO] app::emit; event="log://log"
[2024-12-03][07:20:30][tauri::manager][INFO] app::emit; event="log://log"
[2024-12-03][07:20:30][tauri::manager][INFO] app::emit; event="log://log"
[2024-12-03][07:20:30][tauri::manager][INFO] app::emit; event="log://log"
[2024-12-03][07:20:30][tauri::manager][INFO] app::emit; event="log://log"
[2024-12-03][07:20:30][tauri::manager][INFO] app::emit; event="log://log"
...

This is likely caused by the emit event handler emitting a lot which in turn calls the WebView target handler which calls emit etc..

I'm not sure if there's any config I'm supposed to have set to pre-filter that log message. Either one would need to avoid emit creating any log messages or try to manually not trigger emit on such messages for WebView targets.

Reproduction

No response

Expected behavior

No response

Full tauri info output

cargo tauri info
WARNING: no lock files found, defaulting to npm

[✔] Environment
    - OS: Mac OS 15.1.1 X64
    ✔ Xcode Command Line Tools: installed
    ✔ rustc: 1.82.0-nightly (28a58f2fa 2024-07-31)
    ✔ cargo: 1.82.0-nightly (257b72b8a 2024-07-30)
    ✔ rustup: 1.27.1 (54dd3d00f 2024-04-24)
    ✔ Rust toolchain: nightly-aarch64-apple-darwin (environment override by RUSTUP_TOOLCHAIN)
    - node: 20.10.0
    - yarn: 1.22.19
    - npm: 10.2.4

[-] Packages
    - tauri [RUST]: 2.1.1
    - tauri-build [RUST]: 2.0.3
    - wry [RUST]: 0.47.2
    - tao [RUST]: 0.30.8
    - tauri-cli [RUST]: 2.0.0-beta.20
    - @tauri-apps/api : not installed!
    - @tauri-apps/cli [NPM]: 2.0.0-beta.20 (outdated, latest: 2.1.0)

[-] App
    - build-type: bundle
    - CSP: unset
    - frontendDist: ../dist
    - devUrl: http://localhost:1420/

[-] iOS
    - Developer Teams: ...

Stack trace

No response

Additional context

No response

Legend-Master commented 18 hours ago

I can't reproduce this to be honest, do you have a minimal reproducible example I can test on?

tdomhan commented 17 hours ago

Thanks for taking a look! I'll try see if I can reproduce it in a new tauri app.

tdomhan commented 7 hours ago

I was able to reproduce in a completely new project, but only after adding a dependency for tauri-plugin-devtools = "2.0.0".

This is the full Cargo.toml

[package]
name = "logbug"
version = "0.1.0"
description = "A Tauri App"
authors = ["you"]
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[lib]
# The `_lib` suffix may seem redundant but it is necessary
# to make the lib name unique and wouldn't conflict with the bin name.
# This seems to be only an issue on Windows, see https://github.com/rust-lang/cargo/issues/8519
name = "logbug_lib"
crate-type = ["staticlib", "cdylib", "rlib"]

[build-dependencies]
tauri-build = { version = "2", features = [] }

[dependencies]
tauri = { version = "2", features = ["devtools", "config-json5"] }
tauri-plugin-shell = "2"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
tauri-plugin-log = "2.0.3"
log = "0.4"
tauri-plugin-devtools = "2.0.0"
FabianLars commented 7 hours ago

devtools and the log plugin are currently mutually exclusive because you can only have a single tracing subscriber, but this should actually result in a compilation error 🤔 ref https://docs.crabnebula.dev/devtools/troubleshoot/log-plugins/

tdomhan commented 6 hours ago

ahh good to know thanks for the clarification!