> ## 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

**Developer**

**Federal docs**

**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](https://launchdarkly.com/docs/home/observability/logs.md).

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] Expand iOS code sample
>
> You can use `recordLog` to manually send a custom error:
>
> ```swift title="Record log" lines wrap theme={null}
> LDObserve.shared.recordLog(message: message, severity: .info, attributes: attributes)
> ```
>
> To learn more, read [`recordLog`](https://github.com/launchdarkly/swift-launchdarkly-observability/blob/b792a5c153ea55b0bfd308af35cbd1e8203b30d8/Sources/ApplicationServices/ObservabilityService.swift#L40).

### Android

> [accordion] Expand Android code sample
>
> Use `recordLog` to manually create and send a log record:
>
> ```java title="Record log" lines wrap theme={null}
> LDObserve.recordLog("Example log message", Severity.DEBUG, attributes)
> ```
>
> The attributes argument is optional. To construct it, use `Attributes` from the [`@opentelemetry/api`](https://opentelemetry.io/docs/specs/semconv/general/attributes/).

### Flutter

> [accordion] Expand Flutter code sample
>
> Use `LDObserve.recordLog` to manually create and send a log record with a severity level and optional typed attributes:
>
> ```dart title="Record log" lines wrap theme={null}
> LDObserve.recordLog(
>   'Example log message',
>   severity: LogSeverity.info,
> );
> ```
>
> `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:
>
> ```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,
> );
> ```
>
> When you record a log while a span is active, LaunchDarkly associates the log with that span through the OpenTelemetry context.

### JavaScript

> [accordion] Expand JavaScript code sample
>
> Use `recordLog` to manually create and send a log record:
>
> ```js title="Record log" lines wrap theme={null}
> LDObserve.recordLog('Example log message', Severity.DEBUG);
> ```
>
> To learn more, read [`recordLog`](https://launchdarkly.github.io/observability-sdk/packages/@launchdarkly/observability/interfaces/api_observe.Observe.html#recordlog).

### React Native

> [accordion] Expand React Native code sample
>
> Use `recordLog` to manually create and send a log record:
>
> ```js title="Record log" lines wrap theme={null}
> LDObserve.recordLog('Example log message', Severity.DEBUG, attributes);
> ```
>
> 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).

### 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)
* [Java](#java)
* [Node.js (server-side)](#node-js-server-side)
* [Python](#python)

### .NET (server-side)

> [accordion] Expand .NET (server-side) code sample
>
> Use `RecordLog` to manually create and send a log record.
>
> Here's how:
>
> ```csharp title="Record log" lines wrap theme={null}
> Observe.RecordLog(message, loglevel, attributes)
> ```
>
> 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__).

### Go

> [accordion] 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:
>
> ```go title="Record log" lines wrap theme={null}
> ldobserve.RecordLog(ctx, LogRecord)
> ```
>
> 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).

### Java

> [accordion] Expand Java code sample
>
> Use `LDObserve.recordLog` 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:
>
> ```java title="Record log" lines wrap theme={null}
> LDObserve.recordLog("User logged in", Severity.INFO, Attributes.empty());
> ```
>
> The method takes the message, an OpenTelemetry `Severity`, and `Attributes`, which may include any [attributes from the OpenTelemetry specification](https://opentelemetry.io/docs/specs/semconv/general/attributes/). The plugin only exports records at or above the `logsApiLevel` option, which defaults to `INFO`.
>
> To export the logs your application already writes through Logback or Log4j 2, install the OpenTelemetry appender on the plugin's OpenTelemetry instance. To learn how, read [Export application logs](https://launchdarkly.com/docs/sdk/observability/java.md#export-application-logs).

### Node.js (server-side)

> [accordion] Expand Node.js (server-side) code sample
>
> Use `recordLog` to manually create and send a log record.
>
> Here's how:
>
> ```js title="Record log" lines wrap theme={null}
> LDObserve.recordLog(
>   message,
>   level,
>   secureSessionId,
>   requestId,
>   metadata
> });
> ```
>
> 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).

### Python

> [accordion] 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:
>
> ```python title="Record log" lines wrap theme={null}
> observe.record_log("log message", logging.INFO)
> ```
>
> 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).
