> ## Documentation Index
> Fetch the complete documentation index at: https://launchdarkly.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Sending logs

<View title="Developer" />

<View title="Federal docs" />

<View title="EU docs" />

The observability plugin automatically sends logs to LaunchDarkly. You can also use `recordLog` to manually create and send a log record.

You can view all logs sent to LaunchDarkly under **Logs** in the LaunchDarkly user interface. To learn more, read [Logs](/docs/home/observability/logs).

Details about each SDK's configuration are available in the SDK-specific sections below:

* [Client-side SDKs](#client-side-sdks)
* [Server-side SDKs](#server-side-sdks)

## Client-side SDKs

This feature is available in the observability plugin for the following client-side SDKs:

* [iOS](#ios)
* [Android](#android)
* [Flutter](#flutter)
* [JavaScript](#javascript)
* [React Native](#react-native)
* [React Web](#react-web)
* [Vue](#vue)

### iOS

<Accordion title="Expand iOS code sample">
  You can use `recordLog` to manually send a custom error:

  <CodeGroup>
    ```swift title="Record log" lines wrap theme={null}
    LDObserve.shared.recordLog(message: message, severity: .info, attributes: attributes)
    ```
  </CodeGroup>

  To learn more, read [`recordLog`](https://github.com/launchdarkly/swift-launchdarkly-observability/blob/b792a5c153ea55b0bfd308af35cbd1e8203b30d8/Sources/ApplicationServices/ObservabilityService.swift#L40).
</Accordion>

### Android

<Accordion title="Expand Android code sample">
  Use `recordLog` to manually create and send a log record:

  <CodeGroup>
    ```java title="Record log" lines wrap theme={null}
    LDObserve.recordLog("Example log message", Severity.DEBUG, attributes)
    ```
  </CodeGroup>

  The attributes argument is optional. To construct it, use `Attributes` from the [`@opentelemetry/api`](https://opentelemetry.io/docs/specs/semconv/general/attributes/).
</Accordion>

### Flutter

<Accordion title="Expand Flutter code sample">
  Use `LDObserve.recordLog` to manually create and send a log record with a severity level and optional typed attributes:

  <CodeGroup>
    ```dart title="Record log" lines wrap theme={null}
    LDObserve.recordLog(
      'Example log message',
      severity: LogSeverity.info,
    );
    ```
  </CodeGroup>

  `severity` is a `LogSeverity` value: `trace`, `debug`, `info`, `warn`, `error`, or `fatal`. The default is `LogSeverity.info`.

  You can also attach properties and a stack trace. Properties are a plain Dart map, which means no LaunchDarkly or OpenTelemetry types are required:

  <CodeGroup>
    ```dart title="Record log with properties" lines wrap theme={null}
    LDObserve.recordLog(
      'Checkout completed',
      severity: LogSeverity.info,
      properties: <String, Object?>{
        'order_id': 'ORD-9876',
        'total': 42.99,
      },
      stackTrace: StackTrace.current,
    );
    ```
  </CodeGroup>

  When you record a log while a span is active, LaunchDarkly associates the log with that span through the OpenTelemetry context.
</Accordion>

### JavaScript

<Accordion title="Expand JavaScript code sample">
  Use `recordLog` to manually create and send a log record:

  <CodeGroup>
    ```js title="Record log" lines wrap theme={null}
    LDObserve.recordLog('Example log message', Severity.DEBUG);
    ```
  </CodeGroup>

  To learn more, read [`recordLog`](https://launchdarkly.github.io/observability-sdk/packages/@launchdarkly/observability/interfaces/api_observe.Observe.html#recordlog).
</Accordion>

### React Native

<Accordion title="Expand React Native code sample">
  Use `recordLog` to manually create and send a log record:

  <CodeGroup>
    ```js title="Record log" lines wrap theme={null}
    LDObserve.recordLog('Example log message', Severity.DEBUG, attributes);
    ```
  </CodeGroup>

  The attributes argument is optional. To construct it, use `Attributes` from the [`@opentelemetry/api`](https://opentelemetry.io/docs/specs/semconv/general/attributes/). To learn more, read [`recordLog`](https://launchdarkly.github.io/observability-sdk/sdk/@launchdarkly/observability-react-native/interfaces/Observe.html#recordlog).
</Accordion>

### React Web

To send a log record with the React Web SDK, follow the example for [JavaScript](#javascript).

### Vue

To send a log record with the Vue SDK, follow the example for [JavaScript](#javascript).

## Server-side SDKs

This feature is available in the observability plugin for the following server-side SDKs:

* [.NET (server-side)](#net-server-side)
* [Go](#go)
* [Node.js (server-side)](#node-js-server-side)
* [Python](#python)

### .NET (server-side)

<Accordion title="Expand .NET (server-side) code sample">
  Use `RecordLog` to manually create and send a log record.

  Here's how:

  <CodeGroup>
    ```csharp title="Record log" lines wrap theme={null}
    Observe.RecordLog(message, loglevel, attributes)
    ```
  </CodeGroup>

  You can optionally pass an array of `attributes`, which may include any attributes. We recommend using [attributes from the OpenTelemetry specification](https://opentelemetry.io/docs/specs/semconv/general/attributes/). To learn more, read [`RecordLog`](https://launchdarkly.github.io/observability-sdk/sdk/@launchdarkly/observability-dotnet/api/LaunchDarkly.Observability.Observe.html#LaunchDarkly_Observability_Observe_RecordLog_System_String_Microsoft_Extensions_Logging_LogLevel_System_Collections_Generic_IDictionary_System_String_System_Object__).
</Accordion>

### Go

<Accordion title="Expand Go code sample">
  Use `RecordLog` to manually create and record a log record. The log is recorded with LaunchDarkly, but is not sent to other log handlers.

  Here's how:

  <CodeGroup>
    ```go title="Record log" lines wrap theme={null}
    ldobserve.RecordLog(ctx, LogRecord)
    ```
  </CodeGroup>

  The Go `context.Context` and log record should be specific to this request. You can optionally pass an array of [attributes from the OpenTelemetry specification](https://pkg.go.dev/go.opentelemetry.io/otel/log#KeyValue). To learn more, read [`RecordLog`](https://pkg.go.dev/github.com/launchdarkly/observability-sdk/go#RecordLog).
</Accordion>

### Node.js (server-side)

<Accordion title="Expand Node.js (server-side) code sample">
  Use `recordLog` to manually create and send a log record.

  Here's how:

  <CodeGroup>
    ```js title="Record log" lines wrap theme={null}
    LDObserve.recordLog(
      message,
      level,
      secureSessionId,
      requestId,
      metadata
    });
    ```
  </CodeGroup>

  The `recordLog` method automatically provides context propagation, so you can leave the `secureSessionId` and `requestId` undefined. Alternatively, you have the option to set their values, to assist with the context propagation. You can parse values for `secureSessionId` and `requestId` from the incoming request using [`LDObserve.parseHeaders()`](https://launchdarkly.github.io/observability-sdk/sdk/@launchdarkly/observability-node/interfaces/Observe.html#parseheaders).
</Accordion>

### Python

<Accordion title="Expand Python code sample">
  Use `record_log` to manually create and send a log record. The log is recorded with LaunchDarkly, but is not sent to other log handlers.

  Here's how:

  <CodeGroup>
    ```python title="Record log" lines wrap theme={null}
    observe.record_log("log message", logging.INFO)
    ```
  </CodeGroup>

  The message to record and log level should be specific to this request. You can optionally pass an array of additional `Attributes`, which may include any [attributes from the OpenTelemetry specification](https://opentelemetry.io/docs/specs/semconv/general/attributes/). To learn more, read [`record_log`](https://launchdarkly.github.io/observability-sdk/sdk/@launchdarkly/observability-python/ldobserve/observe.html#record_log).
</Accordion>
