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
Copy file name to clipboardExpand all lines: 3rd-party-integrations/SentrySwiftLog/README.md
+19-96Lines changed: 19 additions & 96 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
-
# Sentry Swift-Log Integration
1
+
# Sentry SwiftLog Integration
2
2
3
-
A `swift-log` handler that forwards log entries to Sentry's structured logging system, automatically capturing application logs with full context including metadata, source location, and log levels.
3
+
A [SwiftLog](https://github.com/apple/swift-log) handler that forwards log entries to Sentry's structured logging system, automatically capturing application logs with full context including metadata, source location, and log levels.
4
4
5
5
> [!NOTE]
6
6
> This repo is a mirror of [github.com/getsentry/sentry-cocoa](https://github.com/getsentry/sentry-cocoa). The source code lives in `3rd-party-integrations/SentrySwiftLog/`. This allows users to import only what they need via SPM while keeping all integration code in the main repository.
@@ -9,104 +9,66 @@ A `swift-log` handler that forwards log entries to Sentry's structured logging s
9
9
10
10
### Swift Package Manager
11
11
12
-
Add the following dependencies to your `Package.swift`:
12
+
Add the following dependencies to your `Package.swift` or Xcode package dependencies:
Set the minimum log level for messages to be sent to Sentry:
53
+
Set the minimum log level for messages to be sent to Sentry. Messages below the configured threshold will be filtered out and not sent to Sentry.
79
54
80
55
```swift
81
-
// Only send info level and above
82
-
let handler =SentryLogHandler(logLevel: .info)
83
-
84
-
// Send all logs including trace and debug
85
56
let handler =SentryLogHandler(logLevel: .trace)
86
57
```
87
58
88
-
Messages below the configured threshold will be filtered out and not sent to Sentry.
89
-
90
59
### Handler Metadata
91
60
92
-
Add metadata that will be included with all log entries:
61
+
Add metadata that will be included with all log entries. Handler metadata is merged with call-site metadata, with call-site metadata taking precedence.
93
62
94
63
```swift
95
64
var handler =SentryLogHandler(logLevel: .info)
96
65
handler.metadata["app_version"] ="1.0.0"
97
66
handler.metadata["environment"] ="production"
98
-
99
-
LoggingSystem.bootstrap { _in handler }
100
67
```
101
68
102
-
Handler metadata is merged with call-site metadata, with call-site metadata taking precedence.
103
-
104
-
### Metadata Subscript Access
105
-
106
69
You can also access metadata using subscript syntax:
107
70
108
71
```swift
109
-
var handler =SentryLogHandler(logLevel: .info)
110
72
handler[metadataKey: "app_version"] ="1.0.0"
111
73
let version = handler[metadataKey: "app_version"]
112
74
```
@@ -127,47 +89,7 @@ let version = handler[metadataKey: "app_version"]
127
89
128
90
## Metadata Handling
129
91
130
-
The handler supports all `swift-log` metadata types:
131
-
132
-
### String Metadata
133
-
134
-
```swift
135
-
logger.info("User action", metadata: [
136
-
"userId":"12345",
137
-
"action":"purchase"
138
-
])
139
-
```
140
-
141
-
### Dictionary Metadata
142
-
143
-
```swift
144
-
logger.info("User profile", metadata: [
145
-
"user": [
146
-
"id":"12345",
147
-
"name":"John Doe"
148
-
]
149
-
])
150
-
```
151
-
152
-
### Array Metadata
153
-
154
-
```swift
155
-
logger.info("Tags", metadata: [
156
-
"tags": ["production", "api", "v2"]
157
-
])
158
-
```
159
-
160
-
### String Convertible Metadata
161
-
162
-
```swift
163
-
logger.info("Metrics", metadata: [
164
-
"count":42,
165
-
"enabled":true,
166
-
"score":3.14159
167
-
])
168
-
```
169
-
170
-
All metadata is automatically prefixed with `swift-log.` in Sentry attributes (e.g., `swift-log.userId`, `swift-log.user.id`).
92
+
The handler supports all `swift-log` metadata types including strings, dictionaries, arrays, and string convertible types (numbers, booleans, etc.). All metadata is automatically prefixed with `swift-log.` in Sentry attributes (e.g., `swift-log.userId`, `swift-log.user.id`). See the Quick Start section above for examples of each metadata type.
171
93
172
94
## Automatic Attributes
173
95
@@ -184,6 +106,7 @@ The handler automatically includes the following attributes with every log entry
0 commit comments