Skip to content

Compatibility with tauri-plugin-log #150

@jeffgardnerdev

Description

@jeffgardnerdev

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.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions