---
title: Electron Log Collection
description: Collect logs from the renderer processes of your Electron applications.
breadcrumbs: >-
  Docs > Log Management > Log Collection and Integrations > Electron Log
  Collection
---

> For the complete documentation index, see [llms.txt](https://docs.datadoghq.com/llms.txt).

# Electron Log Collection

## Overview{% #overview %}

Send logs to Datadog from the renderer processes of your Electron applications. The renderers use the Browser Logs SDK, and the [Electron SDK](https://github.com/DataDog/electron-sdk) in the main process uploads their logs.

{% alert level="info" %}
Log collection is available only in renderer processes. It is not supported in the main process.
{% /alert %}

## Setup{% #setup %}

1. Set up the Electron SDK in the main process by following the [Electron setup instructions](https://docs.datadoghq.com/real_user_monitoring/application_monitoring/electron/setup.md). Logs go through the main process only for renderers listed in [`allowedRendererHosts`](https://docs.datadoghq.com/real_user_monitoring/application_monitoring/electron/advanced_configuration.md#allowed-renderer-hosts).

1. Install `@datadog/browser-logs` in your renderer bundle:

   {% tab title="npm" %}

   ```shell
   npm install @datadog/browser-logs
   ```

   {% /tab %}

   {% tab title="Yarn" %}

   ```shell
   yarn add @datadog/browser-logs
   ```

   {% /tab %}

1. Initialize the Browser Logs SDK in each renderer page that collects logs:

   ```typescript
   import { datadogLogs } from '@datadog/browser-logs';
   
   datadogLogs.init({
     clientToken: '<CLIENT_TOKEN>',
     site: '<DATADOG_SITE>',
     service: '<SERVICE_NAME>',
     forwardErrorsToLogs: true,
   });
   ```

The Browser Logs SDK detects the Electron SDK and sends its logs to the main process, which uploads them.

1. Send logs with the Browser Logs SDK logger API. For loggers, levels, context, and other options, see [Browser Log Collection](https://docs.datadoghq.com/logs/log_collection/javascript.md).

## Sampling{% #sampling %}

Set the sampling of renderer logs with `logsSampleRate` in the main process `init` call. It defaults to `100` and applies independently to each log:

```typescript
await init({
  // ...
  logsSampleRate: 25, // forwards 25% of renderer logs
});
```

`logsSampleRate` is separate from the RUM `sessionSampleRate`. For renderers that send logs through the main process, the Browser Logs SDK ignores its own `sessionSampleRate`. Only `logsSampleRate` in the main process `init` call applies.

## Further Reading{% #further-reading %}

Additional helpful documentation, links, and articles:

- [Source code for electron-sdk](https://github.com/DataDog/electron-sdk)
- [Electron Monitoring](https://docs.datadoghq.com/real_user_monitoring/application_monitoring/electron.md)
- [Learn how to explore your logs](https://docs.datadoghq.com/logs/explorer.md)
