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

Compatibility with tauri-plugin-log #150

Closed
jeffgardnerdev opened this issue Dec 6, 2023 · 3 comments · Fixed by #337 · May be fixed by #158
Closed

Compatibility with tauri-plugin-log #150

jeffgardnerdev opened this issue Dec 6, 2023 · 3 comments · Fixed by #337 · May be fixed by #158
Assignees

Comments

@jeffgardnerdev
Copy link

jeffgardnerdev commented Dec 6, 2023

The Tauri log plugin is widely used, but cannot coexist with devtools--this panic error crashes the app on startup when both plugins are added:
error while running tauri application: PluginInitialization("log", "attempted to set a logger after the logging system was already initialized")

This can be worked around by only adding the devtools plugin in development and only adding the log plugin in production, like so:

    let builder = tauri::Builder::default();

    #[cfg(debug_assertions)]
    let builder = builder.plugin(devtools::init());
    
    #[cfg(not(debug_assertions))]
    let builder = builder.plugin(
        tauri_plugin_log::Builder::default()
            # example log plugin config below
            .targets([LogTarget::Stdout, LogTarget::LogDir])
            .with_colors(ColoredLevelConfig::default())
            .level_for("tauri", LevelFilter::Info)
            .level(LevelFilter::Info)
            .build(),
    );
    
    builder
        .plugin(...) # other plugins
        .invoke_handler(tauri::generate_handler![
            ... # handlers
        ])
        ... # other stuff
        .run(tauri::generate_context!())
        .expect("error while running tauri application");

But this doesn't account for any log statements made on the JS side, like this:

import { debug } from 'tauri-plugin-log-api';
debug('debug log entry');

Ideally there would be some way to seamlessly redirect log entries to devtools in development while retaining normal log plugin behavior in production.

@CrabNejonas
Copy link
Contributor

Yeah okay so I played around with this somewhat yesterday and I really like your suggestion of making it compatible with the log plugins js functions. However, creating tracing::Metadata objects seems to be a bit tricky :/ will report back when I make further progress

@CrabNejonas
Copy link
Contributor

Okay so turns out I was overcomplicating things 😄 and adding compat with tauri-plugin-log meant that I realized a way to make the output of messages generated through log much more useful in general!

@tance77
Copy link

tance77 commented Apr 17, 2024

I have the same issue as @jeffgardnerdev. There doesn't seem to be a way to configure logs when this is added as a plugin. I have logs everywhere even in production so I get a lot of errors when I do not configure tauri_plugin_log.

Neat tool you have here though.

lucasfernog-crabnebula added a commit that referenced this issue Jul 25, 2024
…patibility

feat: compatibility with tauri-plugin-log, closes #150
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants