Skip to content
Tauri

Logging

Configurable logging for your Tauri app.

Supported Platforms

  • Windows
  • Linux
  • macOS
  • iOS

Setup

This plugin requires a Rust version of at least 1.75

Install the log plugin to get started.

Use your project’s package manager to add the dependency:

npm run tauri add log

Usage

  1. First, you need to register the plugin with Tauri.

    src-tauri/src/lib.rs
    use tauri_plugin_log::{Target, TargetKind};
    #[cfg_attr(mobile, tauri::mobile_entry_point)]
    pub fn run() {
    tauri::Builder::default()
    .plugin(
    tauri_plugin_log::Builder::new()
    .targets([
    Target::new(TargetKind::Stdout),
    Target::new(TargetKind::LogDir { file_name: None }),
    Target::new(TargetKind::Webview),
    ])
    .build(),
    )
    .run(tauri::generate_context!())
    .expect("error while running tauri application");
    }
  2. Afterwards, all the plugin’s APIs are available through the JavaScript guest bindings:

    import { trace, info, error, attachConsole } from '@tauri-apps/plugin-log';
    // with TargetKind::Webview enabled, this function will print logs to the browser console
    const detach = await attachConsole();
    trace('Trace');
    info('Info');
    error('Error');
    // detach the browser console from the log stream
    detach();

Permissions

By default, all plugin commands are blocked and cannot be accessed. You must define a list of permissions in your capabilities configuration.

See Permissions Overview for more information.

src-tauri/capabilities/main.json
{
"$schema": "../gen/schemas/desktop-schema.json",
"identifier": "main-capability",
"description": "Capability for the main window",
"windows": ["main"],
"permissions": ["log:default"]
}
PermissionDescription
log:defaultAllows the log command.
log:allow-logEnables the log command without any pre-configured scope.
log:deny-logDenies the log command without any pre-configured scope.

© 2024 Tauri Contributors. CC-BY / MIT