Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
tdomhan opened this issue Dec 3, 2024 · 18 comments
Open

Comments

@tdomhan
Copy link

tdomhan commented Dec 3, 2024

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 Legend-Master transferred this issue from tauri-apps/tauri Dec 3, 2024
@Legend-Master
Copy link
Contributor

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

@tdomhan
Copy link
Author

tdomhan commented Dec 3, 2024

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

@tdomhan
Copy link
Author

tdomhan commented Dec 3, 2024

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
Copy link
Member

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
Copy link
Author

tdomhan commented Dec 3, 2024

ahh good to know thanks for the clarification!

@tdomhan
Copy link
Author

tdomhan commented Dec 4, 2024

ah it's probably worth pointing out that I only had the devtools feature turned on and the devtools plugin dependency addded but without adding the devtools plugin to the app:

#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
    tauri::Builder::default()
        .plugin(tauri_plugin_shell::init())
        .plugin(
            tauri_plugin_log::Builder::new()
                .targets([Target::new(TargetKind::Stdout), Target::new(TargetKind::Webview)])
                .level(LevelFilter::Info)
                .build(),
        )
        .invoke_handler(tauri::generate_handler![greet])
        .run(tauri::generate_context!())
        .expect("error while running tauri application");
    log::info!("hi");    
}

@Legend-Master
Copy link
Contributor

I'm not familiar with devtools but seems like it enabled tauri's tracing feature as well as log feature from tracing crate which makes tracing events to be converted to log events

@tdomhan
Copy link
Author

tdomhan commented Dec 4, 2024

That's right. Although that alone doesn't trigger the problem which only arises when also adding the devtools plugin dependency.

@ayangweb
Copy link
Contributor

ayangweb commented Dec 6, 2024

I also experienced loop errors, which began when the log plugin was updated from 2.0.0 to 2.0.1.

image

@ayangweb
Copy link
Contributor

ayangweb commented Dec 6, 2024

@Legend-Master

return filtered[2].filter((v) => v.length > 0).join('@')

The error reported happens to be this line of code!

@Legend-Master
Copy link
Contributor

@ayangweb well, I think this is another bug, probably you're logging uncaught errors and the log itself threw, I will open a fix for that right now

@ayangweb
Copy link
Contributor

ayangweb commented Dec 6, 2024

@Legend-Master Overwrote and printed it to see if it helps you.

image

@Legend-Master
Copy link
Contributor

@Legend-Master Overwrote and printed it to see if it helps you.

image

Could you also log out stack?

@ayangweb
Copy link
Contributor

ayangweb commented Dec 6, 2024

@Legend-Master Overwrote and printed it to see if it helps you.
image

Could you also log out stack?

I don't understand what you mean by that.

@Legend-Master
Copy link
Contributor

this variable

image

@ayangweb
Copy link
Contributor

ayangweb commented Dec 6, 2024

@Legend-Master
image

@Legend-Master
Copy link
Contributor

Do you mind just copy the string in so I can see the full thing? I think the problems is probably @tauri-apps also contains an @

@ayangweb
Copy link
Contributor

ayangweb commented Dec 6, 2024

Do you mind just copy the string in so I can see the full thing? I think the problems is probably @tauri-apps also contains an @

"@http://localhost:1420/node_modules/.vite/deps/@tauri-apps_plugin-log.js:50:47
log@http://localhost:1420/node_modules/.vite/deps/@tauri-apps_plugin-log.js:49:20
@http://localhost:1420/node_modules/.vite/deps/@tauri-apps_plugin-log.js:62:12
error@http://localhost:1420/node_modules/.vite/deps/@tauri-apps_plugin-log.js:61:22
@http://localhost:1420/src/App.tsx:83:10"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants