All jobs

Add Logging to a Tauri App with tauri-plugin-log

Yes. An agent replaces println in your Tauri app with tauri-plugin-log writing to stdout, a log file and the webview console, grants the permission, and opens a PR.

Run this on RushOpens the console with this prompt ready to send, in a Project that has your repository.

What the agent does

The agent reads both halves of the app before choosing where logs go. In a project laid out like Uninen/tauri-vue-template, src-tauri/src/lib.rs has one command, greet, whose only output is println!("Backend was called with an argument: {}", name), and a run function that builds tauri::Builder::default(), opens devtools in a setup closure on debug builds, registers tauri_plugin_shell and tauri_plugin_prevent_default, and installs greet as the invoke handler. src-tauri/src/main.rs sets windows_subsystem = "windows" on release builds, so on Windows that println! has no console to land in. Cargo.toml depends on tauri 2, tauri-plugin-shell 2, serde, serde_json and tauri-plugin-prevent-default 5.0, with no log crate; the lockfile resolves tauri at 2.10.3. tauri.conf.json names the app tauri-app with identifier com.tauri-app.my, and there is no src-tauri/capabilities/ directory at all. On the frontend, src/components/GreetComponent.vue calls invoke('greet', { name }), src/store.ts does console.log('app initialized!') in a Pinia action, src/main.ts connects Vue devtools in development, package.json runs pnpm check for cargo check against the Tauri manifest and pnpm test for Vitest, .github/renovate.json groups cargo and npm updates, and test-build.yml installs libwebkit2gtk-4.1-dev and friends before pnpm tauri build on Ubuntu 24.04.

On the Rust side the agent runs cargo add tauri-plugin-log log inside src-tauri and registers the plugin in run with tauri_plugin_log::Builder::new(), a target list of TargetKind::Stdout, TargetKind::LogDir { file_name: Some("tauri-app".into()) } and TargetKind::Webview, a level of Debug under debug_assertions and Info otherwise, and a max_file_size with a rotation_strategy so the file cannot grow without bound. The println! in greet becomes log::info! with the same message, and the setup closure logs that devtools opened. Because the template has no capabilities directory, the agent creates src-tauri/capabilities/default.json with the main window and the permissions core:default and log:default, since the frontend side of the plugin invokes plugin:log|log and is denied without it; greet, an application command rather than a plugin command, is not governed by that file and keeps working.

On the frontend the agent adds @tauri-apps/plugin-log with pnpm add and writes a small src/log.ts that exports info, warn and error: inside Tauri, detected by '__TAURI_INTERNALS__' in window, they call the plugin, and outside it, which is where Vitest and a plain vite dev server run, they fall back to the console, so pnpm test needs no mock. src/main.ts calls attachConsole() in development so Rust log lines appear in the webview console next to the Vue devtools output, and the console.log in store.ts becomes info from the wrapper. CHANGES.md, which the template keeps as a changelog, gets an entry.

To build the Rust side the sandbox needs the same system libraries the build workflow installs, so the agent runs that apt-get install line, then pnpm install, pnpm check, cargo clippy in src-tauri, pnpm build for vue-tsc and Vite, and pnpm test. It then runs pnpm tauri build --debug and launches the binary under a virtual display long enough to confirm a file appears at ~/.local/share/com.tauri-app.my/logs/tauri-app.log, the Linux path the LogDir target writes to, and that it contains the setup line.

Start it with one API call

POST https://api.phoenix.so/o/{org}/sessions with this body:

{
  "agent": "claude",
  "input": "Add logging to this Tauri 2 app with tauri-plugin-log. Read src-tauri/Cargo.toml, src-tauri/src/lib.rs, src-tauri/src/main.rs, src-tauri/tauri.conf.json, src/main.ts, src/store.ts, src/components/GreetComponent.vue, package.json, vitest.config.ts, CHANGES.md and .github/workflows/test-build.yml first. In src-tauri run cargo add tauri-plugin-log log, register the plugin in run with Stdout, LogDir and Webview targets, Debug level on debug builds and Info otherwise, and a max file size with rotation; replace the println in greet with log::info. The template has no capabilities directory: create src-tauri/capabilities/default.json for the main window with core:default and log:default. Add @tauri-apps/plugin-log with pnpm, write src/log.ts that uses the plugin inside Tauri and falls back to console elsewhere so Vitest needs no mock, call attachConsole in development from main.ts, and replace the console.log in store.ts. Add a CHANGES.md entry. Install the webkit2gtk build dependencies from test-build.yml, run pnpm install, pnpm check, cargo clippy, pnpm build and pnpm test, build with pnpm tauri build --debug, launch the binary under a virtual display and confirm the log file appears under ~/.local/share/com.tauri-app.my/logs. Open a pull request with the file's first lines in its description.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
  1. Get an API key. In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
  2. Send the request. POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
  3. Read what came back. Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

What comes back

The pull request changes src-tauri/Cargo.toml and Cargo.lock, src-tauri/src/lib.rs, package.json and pnpm-lock.yaml, src/main.ts and src/store.ts, adds src-tauri/capabilities/default.json and src/log.ts, and appends to CHANGES.md. Its description pastes the cargo clippy and pnpm test output, the path of the log file the debug build produced under the virtual display, and its first lines, and names the platform-specific paths the LogDir target uses on macOS and Windows.

Before merging, a reviewer decides whether Stdout should stay on in release builds, whether the file size and rotation values suit how long a user keeps the app open, and whether Webview should be limited to development, since every Rust log line otherwise reaches the user's devtools.

Run it on every Tauri repository

A team with several Tauri apps sends this body once per repository from its own server, each a POST /o/{org}/sessions with that repository in resources and a request_id that is a UUID v5 of the repository's full name, so a retried call returns the run already started. Each run reads its own project: one that already has a capabilities directory gets log:default added to the existing file, one on tauri-plugin-log already gets a note and no change, and a React or Svelte frontend gets the same log.ts wrapper with its own import style.

Once logging is in, an automation on the Project with a github trigger on pull_request.opened and the prompt "if this pull request adds a println or console.log under src-tauri or src, comment with the line and the log call to use instead" starts one run per pull request. The trigger adds the pull request after the prompt, and only work by an owner, member or collaborator fires it.

The use case this job follows, with its automation and trigger: Hand off a long task.

Why run it on Rush?

Desktop logging is where a template's defaults quietly fail: println! is invisible on Windows release builds, the webview console is gone once the window closes, and a plugin added without its capability entry is denied at the first call with a message many developers read as a build problem. The agent reads both processes, grants exactly the permission the plugin needs, and builds the app to confirm the file is written.

Building a Tauri app needs the system libraries, the Rust toolchain and a display to launch it, which the agent sets up in its own sandbox; the clippy, test and build output and the first lines of the resulting log file stay with the run. The same request runs across every Tauri app a team maintains, each in its own sandbox.

Frequently asked questions

Why create a capabilities file when the app worked without one?

Commands the app defines itself, like greet, are not governed by capabilities unless the build script opts them in, which is why invoke('greet') works today with no capabilities directory. Plugin commands are governed, and the frontend half of the log plugin calls one, so log:default has to be granted to the main window or every info() from the frontend is refused.

Will Vitest break because the plugin is not available in tests?

No. src/log.ts checks for __TAURI_INTERNALS__ on window and uses the console when it is absent, which is the case under Vitest and under a plain vite dev server. The plugin module is only called inside the real app, so the existing test and any new one need no mock.

Where does the log file go?

The LogDir target writes under the platform's log directory for the bundle identifier com.tauri-app.my: ~/.local/share/com.tauri-app.my/logs on Linux, the user's Library/Logs folder on macOS and the local app data folder on Windows. The file name is the one set in the target, and rotation keeps it from growing without limit.

Does Renovate pick up the new packages?

Yes. .github/renovate.json already enables the cargo and npm managers and groups their updates, so tauri-plugin-log, log and @tauri-apps/plugin-log join the existing cargo and front-end groups with the same three-day minimum release age.

More Tauri jobs

More jobs like this: Hand off a long task

Keep reading