# Log Forwarding

Capture and forward logs from your Dioxus application to WebdriverIO's logger system.

## Overview[​](#overview "Direct link to Overview")

The Dioxus service can capture and forward logs from both the Rust backend and the frontend webview console to WebdriverIO's logger system. This allows you to see Dioxus application logs seamlessly integrated with your test output.

## Enabling Log Forwarding[​](#enabling-log-forwarding "Direct link to Enabling Log Forwarding")

Log forwarding is disabled by default. Enable it via service options:

```
// wdio.conf.ts
export const config = {
  services: [
    ['@wdio/dioxus-service', {
      captureBackendLogs: true,      // Capture Rust logs from the app process
      captureFrontendLogs: true,     // Capture console logs from the webview
      backendLogLevel: 'info',       // Minimum backend log level (default: 'info')
      frontendLogLevel: 'info',      // Minimum frontend log level (default: 'info')
    }],
  ],
  capabilities: [
    {
      browserName: 'dioxus',
      'dioxus:options': {
        application: './target/debug/my_app',
      },
    },
  ],
};
```

## Log Levels[​](#log-levels "Direct link to Log Levels")

Both backend and frontend log capture support the following log levels (in order of priority):

* `trace` - Most verbose
* `debug` - Debug information
* `info` - Informational messages (default)
* `warn` - Warning messages
* `error` - Error messages

Only logs at the configured level and above will be captured. For example, with `backendLogLevel: 'info'`, only `info`, `warn`, and `error` logs are captured.

## Log Format[​](#log-format "Direct link to Log Format")

Captured logs are formatted with context tags:

* Backend logs: `[Dioxus:Backend] message`
* Frontend logs: `[Dioxus:Frontend] message`
* Multiremote logs: `[Dioxus:Backend:instanceId] message` / `[Dioxus:Frontend:instanceId] message`

## Backend Log Capture[​](#backend-log-capture "Direct link to Backend Log Capture")

Backend log capture reads Rust logs from the Dioxus application process. These logs are generated using the Rust `log` crate:

```
// In your Dioxus app (add log crate to Cargo.toml)
log::info!("This is an info log");
log::warn!("This is a warning");
log::error!("This is an error");
```

Enable the `log` crate in your `Cargo.toml`:

```
[dependencies]
dioxus = { version = "0.6", features = ["desktop"] }
log = "0.4"
```

> **Note:** The `log` crate is a no-op façade until a concrete backend registers itself as the global logger. During WDIO test runs, `wdio-dioxus-bridge` installs its own subscriber automatically. For non-WDIO runs (development, production), add a backend such as `tracing-subscriber` or `env_logger` so your `log::*!()` calls produce output.

The service automatically filters driver-level logs and only captures logs from your Dioxus application.

## Frontend Log Capture[​](#frontend-log-capture "Direct link to Frontend Log Capture")

Frontend log capture uses the WebDriver `getLogs` API to retrieve console logs from the webview:

```
// In your Dioxus frontend (JavaScript/TypeScript)
console.info('This is an info log');
console.warn('This is a warning');
console.error('This is an error');
```

Frontend logs are captured periodically and before each WebDriver command.

## Independent Configuration[​](#independent-configuration "Direct link to Independent Configuration")

Backend and frontend log capture can be configured independently:

```
services: [
  ['@wdio/dioxus-service', {
    captureBackendLogs: true,
    captureFrontendLogs: false,
    backendLogLevel: 'debug',
  }],
],
```

## Multiremote Support[​](#multiremote-support "Direct link to Multiremote Support")

In multiremote scenarios, logs are captured per instance with instance IDs in the log context:

```
capabilities: {
  browserA: {
    browserName: 'dioxus',
    'dioxus:options': {
      application: './target/debug/my_app',
    },
  },
  browserB: {
    browserName: 'dioxus',
    'dioxus:options': {
      application: './target/debug/my_app',
    },
  },
},

services: [
  ['@wdio/dioxus-service', {
    captureBackendLogs: true,
    captureFrontendLogs: true,
  }],
],
```

Logs will appear as:

* `[Dioxus:Backend:browserA] message`
* `[Dioxus:Frontend:browserB] message`

## Performance Considerations[​](#performance-considerations "Direct link to Performance Considerations")

* Log capture is optional and disabled by default to avoid overhead.
* Frontend log capture uses periodic polling (every 1 second) which has minimal performance impact.
* Backend log parsing is efficient and non-blocking.
* Log level filtering reduces the number of logs processed.

## Troubleshooting[​](#troubleshooting "Direct link to Troubleshooting")

### Logs not appearing[​](#logs-not-appearing "Direct link to Logs not appearing")

* Ensure `captureBackendLogs` or `captureFrontendLogs` is set to `true`.
* Check that your log level is appropriate (logs below the configured level won't appear).
* Verify logs are being written to stdout (backend) or console (frontend).
* For backend logs: ensure the `log` crate is properly initialized in your Rust app.

### Too many logs[​](#too-many-logs "Direct link to Too many logs")

* Increase the log level (e.g., from `debug` to `info`) to filter out verbose logs.
* Disable log capture for one source if you only need backend or frontend logs.

### Frontend logs not captured[​](#frontend-logs-not-captured "Direct link to Frontend logs not captured")

* Some WebDriver implementations may not support the `getLogs` API.
* The service will silently fail if `getLogs` is not supported.
* Backend logs will still work in this case.

## See Also[​](#see-also "Direct link to See Also")

* [Configuration](/docs/desktop-testing/dioxus/configuration.md) for all service options
* [Usage Examples](/docs/desktop-testing/dioxus/usage-examples.md) for logging patterns
* [Troubleshooting](/docs/desktop-testing/dioxus/troubleshooting.md) for common issues
