1
- import type { LogSeverityLevel , Log , Client } from '@sentry/core' ;
1
+ import type { LogSeverityLevel , Log , Client , ParameterizedString } from '@sentry/core' ;
2
2
import { getClient , _INTERNAL_captureLog , _INTERNAL_flushLogsBuffer } from '@sentry/core' ;
3
3
4
4
import { WINDOW } from './helpers' ;
@@ -59,7 +59,7 @@ function addFlushingListeners(client: Client): void {
59
59
*/
60
60
function captureLog (
61
61
level : LogSeverityLevel ,
62
- message : string ,
62
+ message : ParameterizedString ,
63
63
attributes ?: Log [ 'attributes' ] ,
64
64
severityNumber ?: Log [ 'severityNumber' ] ,
65
65
) : void {
@@ -77,110 +77,216 @@ function captureLog(
77
77
* @summary Capture a log with the `trace` level. Requires `_experiments.enableLogs` to be enabled.
78
78
*
79
79
* @param message - The message to log.
80
- * @param attributes - Arbitrary structured data that stores information about the log - e.g., userId: 100.
80
+ * @param attributes - Arbitrary structured data that stores information about the log - e.g., { userId: 100, route: '/dashboard' } .
81
81
*
82
82
* @example
83
83
*
84
84
* ```
85
- * Sentry.logger.trace('Hello world', { userId: 100 });
85
+ * Sentry.logger.trace('User clicked submit button', {
86
+ * buttonId: 'submit-form',
87
+ * formId: 'user-profile',
88
+ * timestamp: Date.now()
89
+ * });
90
+ * ```
91
+ *
92
+ * @example With template strings
93
+ *
94
+ * ```
95
+ * Sentry.logger.trace(Sentry.logger.fmt`User ${user} navigated to ${page}`, {
96
+ * userId: '123',
97
+ * sessionId: 'abc-xyz'
98
+ * });
86
99
* ```
87
100
*/
88
- export function trace ( message : string , attributes ?: Log [ 'attributes' ] ) : void {
101
+ export function trace ( message : ParameterizedString , attributes ?: Log [ 'attributes' ] ) : void {
89
102
captureLog ( 'trace' , message , attributes ) ;
90
103
}
91
104
92
105
/**
93
106
* @summary Capture a log with the `debug` level. Requires `_experiments.enableLogs` to be enabled.
94
107
*
95
108
* @param message - The message to log.
96
- * @param attributes - Arbitrary structured data that stores information about the log - e.g., userId: 100 .
109
+ * @param attributes - Arbitrary structured data that stores information about the log - e.g., { component: 'Header', state: 'loading' } .
97
110
*
98
111
* @example
99
112
*
100
113
* ```
101
- * Sentry.logger.debug('Hello world', { userId: 100 });
114
+ * Sentry.logger.debug('Component mounted', {
115
+ * component: 'UserProfile',
116
+ * props: { userId: 123 },
117
+ * renderTime: 150
118
+ * });
119
+ * ```
120
+ *
121
+ * @example With template strings
122
+ *
123
+ * ```
124
+ * Sentry.logger.debug(Sentry.logger.fmt`API request to ${endpoint} failed`, {
125
+ * statusCode: 404,
126
+ * requestId: 'req-123',
127
+ * duration: 250
128
+ * });
102
129
* ```
103
130
*/
104
- export function debug ( message : string , attributes ?: Log [ 'attributes' ] ) : void {
131
+ export function debug ( message : ParameterizedString , attributes ?: Log [ 'attributes' ] ) : void {
105
132
captureLog ( 'debug' , message , attributes ) ;
106
133
}
107
134
108
135
/**
109
136
* @summary Capture a log with the `info` level. Requires `_experiments.enableLogs` to be enabled.
110
137
*
111
138
* @param message - The message to log.
112
- * @param attributes - Arbitrary structured data that stores information about the log - e.g., userId: 100 .
139
+ * @param attributes - Arbitrary structured data that stores information about the log - e.g., { feature: 'checkout', status: 'completed' } .
113
140
*
114
141
* @example
115
142
*
116
143
* ```
117
- * Sentry.logger.info('Hello world', { userId: 100 });
144
+ * Sentry.logger.info('User completed checkout', {
145
+ * orderId: 'order-123',
146
+ * amount: 99.99,
147
+ * paymentMethod: 'credit_card'
148
+ * });
149
+ * ```
150
+ *
151
+ * @example With template strings
152
+ *
153
+ * ```
154
+ * Sentry.logger.info(Sentry.logger.fmt`User ${user} updated profile picture`, {
155
+ * userId: 'user-123',
156
+ * imageSize: '2.5MB',
157
+ * timestamp: Date.now()
158
+ * });
118
159
* ```
119
160
*/
120
- export function info ( message : string , attributes ?: Log [ 'attributes' ] ) : void {
161
+ export function info ( message : ParameterizedString , attributes ?: Log [ 'attributes' ] ) : void {
121
162
captureLog ( 'info' , message , attributes ) ;
122
163
}
123
164
124
165
/**
125
166
* @summary Capture a log with the `warn` level. Requires `_experiments.enableLogs` to be enabled.
126
167
*
127
168
* @param message - The message to log.
128
- * @param attributes - Arbitrary structured data that stores information about the log - e.g., userId: 100 .
169
+ * @param attributes - Arbitrary structured data that stores information about the log - e.g., { browser: 'Chrome', version: '91.0' } .
129
170
*
130
171
* @example
131
172
*
132
173
* ```
133
- * Sentry.logger.warn('Hello world', { userId: 100 });
174
+ * Sentry.logger.warn('Browser compatibility issue detected', {
175
+ * browser: 'Safari',
176
+ * version: '14.0',
177
+ * feature: 'WebRTC',
178
+ * fallback: 'enabled'
179
+ * });
180
+ * ```
181
+ *
182
+ * @example With template strings
183
+ *
184
+ * ```
185
+ * Sentry.logger.warn(Sentry.logger.fmt`API endpoint ${endpoint} is deprecated`, {
186
+ * recommendedEndpoint: '/api/v2/users',
187
+ * sunsetDate: '2024-12-31',
188
+ * clientVersion: '1.2.3'
189
+ * });
134
190
* ```
135
191
*/
136
- export function warn ( message : string , attributes ?: Log [ 'attributes' ] ) : void {
192
+ export function warn ( message : ParameterizedString , attributes ?: Log [ 'attributes' ] ) : void {
137
193
captureLog ( 'warn' , message , attributes ) ;
138
194
}
139
195
140
196
/**
141
197
* @summary Capture a log with the `error` level. Requires `_experiments.enableLogs` to be enabled.
142
198
*
143
199
* @param message - The message to log.
144
- * @param attributes - Arbitrary structured data that stores information about the log - e.g., userId: 100 .
200
+ * @param attributes - Arbitrary structured data that stores information about the log - e.g., { error: 'NetworkError', url: '/api/data' } .
145
201
*
146
202
* @example
147
203
*
148
204
* ```
149
- * Sentry.logger.error('Hello world', { userId: 100 });
205
+ * Sentry.logger.error('Failed to load user data', {
206
+ * error: 'NetworkError',
207
+ * url: '/api/users/123',
208
+ * statusCode: 500,
209
+ * retryCount: 3
210
+ * });
211
+ * ```
212
+ *
213
+ * @example With template strings
214
+ *
215
+ * ```
216
+ * Sentry.logger.error(Sentry.logger.fmt`Payment processing failed for order ${orderId}`, {
217
+ * error: 'InsufficientFunds',
218
+ * amount: 100.00,
219
+ * currency: 'USD',
220
+ * userId: 'user-456'
221
+ * });
150
222
* ```
151
223
*/
152
- export function error ( message : string , attributes ?: Log [ 'attributes' ] ) : void {
224
+ export function error ( message : ParameterizedString , attributes ?: Log [ 'attributes' ] ) : void {
153
225
captureLog ( 'error' , message , attributes ) ;
154
226
}
155
227
156
228
/**
157
229
* @summary Capture a log with the `fatal` level. Requires `_experiments.enableLogs` to be enabled.
158
230
*
159
231
* @param message - The message to log.
160
- * @param attributes - Arbitrary structured data that stores information about the log - e.g., userId: 100 .
232
+ * @param attributes - Arbitrary structured data that stores information about the log - e.g., { appState: 'corrupted', sessionId: 'abc-123' } .
161
233
*
162
234
* @example
163
235
*
164
236
* ```
165
- * Sentry.logger.fatal('Hello world', { userId: 100 });
237
+ * Sentry.logger.fatal('Application state corrupted', {
238
+ * lastKnownState: 'authenticated',
239
+ * sessionId: 'session-123',
240
+ * timestamp: Date.now(),
241
+ * recoveryAttempted: true
242
+ * });
243
+ * ```
244
+ *
245
+ * @example With template strings
246
+ *
247
+ * ```
248
+ * Sentry.logger.fatal(Sentry.logger.fmt`Critical system failure in ${service}`, {
249
+ * service: 'payment-processor',
250
+ * errorCode: 'CRITICAL_FAILURE',
251
+ * affectedUsers: 150,
252
+ * timestamp: Date.now()
253
+ * });
166
254
* ```
167
255
*/
168
- export function fatal ( message : string , attributes ?: Log [ 'attributes' ] ) : void {
256
+ export function fatal ( message : ParameterizedString , attributes ?: Log [ 'attributes' ] ) : void {
169
257
captureLog ( 'fatal' , message , attributes ) ;
170
258
}
171
259
172
260
/**
173
261
* @summary Capture a log with the `critical` level. Requires `_experiments.enableLogs` to be enabled.
174
262
*
175
263
* @param message - The message to log.
176
- * @param attributes - Arbitrary structured data that stores information about the log - e.g., userId: 100 .
264
+ * @param attributes - Arbitrary structured data that stores information about the log - e.g., { security: 'breach', severity: 'high' } .
177
265
*
178
266
* @example
179
267
*
180
268
* ```
181
- * Sentry.logger.critical('Hello world', { userId: 100 });
269
+ * Sentry.logger.critical('Security breach detected', {
270
+ * type: 'unauthorized_access',
271
+ * user: '132123',
272
+ * endpoint: '/api/admin',
273
+ * timestamp: Date.now()
274
+ * });
275
+ * ```
276
+ *
277
+ * @example With template strings
278
+ *
279
+ * ```
280
+ * Sentry.logger.critical(Sentry.logger.fmt`Multiple failed login attempts from user ${user}`, {
281
+ * attempts: 10,
282
+ * timeWindow: '5m',
283
+ * blocked: true,
284
+ * timestamp: Date.now()
285
+ * });
182
286
* ```
183
287
*/
184
- export function critical ( message : string , attributes ?: Log [ 'attributes' ] ) : void {
288
+ export function critical ( message : ParameterizedString , attributes ?: Log [ 'attributes' ] ) : void {
185
289
captureLog ( 'critical' , message , attributes ) ;
186
290
}
291
+
292
+ export { fmt } from '@sentry/core' ;
0 commit comments