You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
description: "Structured logs allow you to send, view and query logs sent from your applications within Sentry."
5
+
sidebar_order: 5755
6
+
---
7
+
8
+
<Includename="feature-stage-beta-logs.mdx" />
9
+
10
+
With Sentry Structured Logs, you can send text based log information from your applications to Sentry. Once in Sentry, these logs can be viewed alongside relevant errors, searched by text-string, or searched using their individual attributes.
The `beforeSendLog` function receives a log object, and should return the log object if you want it to be sent to Sentry, or `nil` if you want to discard it.
Logs for Apple platforms are supported in Sentry Cocoa SDK version `8.55.0` and above. Logs are still experimental and the API may change in the future.
Once the feature is enabled on the SDK and the SDK is initialized, you can send logs using the `Sentry.logger` APIs.
2
+
3
+
The `Sentry.logger` namespace exposes six methods that you can use to log messages at different log levels: `trace`, `debug`, `info`, `warn`, `error`, and `fatal`. Supported types for attributes are Strings, Int, Double, and Bool.
[logger warn:@"Rate limit reached for endpoint" attributes:@{
48
+
@"endpoint": @"/api/results/",
49
+
@"isEnterprise": @NO
50
+
}];
51
+
[logger error:@"Failed to process payment" attributes:@{
52
+
@"orderId": @"order_123",
53
+
@"amount": @99.99
54
+
}];
55
+
[logger fatal:@"Database connection pool exhausted" attributes:@{
56
+
@"database": @"users",
57
+
@"activeConnections": @100
58
+
}];
59
+
```
60
+
61
+
### String Interpolation (Swift Only)
62
+
63
+
Swift supports automatic extraction of interpolated values as attributes. When you use string interpolation in your log messages, supported types (Strings, Int, Double, and Bool) are automatically extracted and added as attributes with the key format `sentry.message.parameter.{index}`.
64
+
65
+
```swift
66
+
let userId = "user_123"
67
+
let orderCount = 5
68
+
let isPremium = true
69
+
let totalAmount = 99.99
70
+
71
+
// String interpolation automatically extracts values as attributes
0 commit comments