1- import type { LogSeverityLevel , Log , Client } from '@sentry/core' ;
1+ import type { LogSeverityLevel , Log , Client , ParameterizedString } from '@sentry/core' ;
22import { getClient , _INTERNAL_captureLog , _INTERNAL_flushLogsBuffer } from '@sentry/core' ;
33
44import { WINDOW } from './helpers' ;
@@ -59,7 +59,7 @@ function addFlushingListeners(client: Client): void {
5959 */
6060function captureLog (
6161 level : LogSeverityLevel ,
62- message : string ,
62+ message : ParameterizedString ,
6363 attributes ?: Log [ 'attributes' ] ,
6464 severityNumber ?: Log [ 'severityNumber' ] ,
6565) : void {
@@ -77,110 +77,216 @@ function captureLog(
7777 * @summary Capture a log with the `trace` level. Requires `_experiments.enableLogs` to be enabled.
7878 *
7979 * @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' } .
8181 *
8282 * @example
8383 *
8484 * ```
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+ * });
8699 * ```
87100 */
88- export function trace ( message : string , attributes ?: Log [ 'attributes' ] ) : void {
101+ export function trace ( message : ParameterizedString , attributes ?: Log [ 'attributes' ] ) : void {
89102 captureLog ( 'trace' , message , attributes ) ;
90103}
91104
92105/**
93106 * @summary Capture a log with the `debug` level. Requires `_experiments.enableLogs` to be enabled.
94107 *
95108 * @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' } .
97110 *
98111 * @example
99112 *
100113 * ```
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+ * });
102129 * ```
103130 */
104- export function debug ( message : string , attributes ?: Log [ 'attributes' ] ) : void {
131+ export function debug ( message : ParameterizedString , attributes ?: Log [ 'attributes' ] ) : void {
105132 captureLog ( 'debug' , message , attributes ) ;
106133}
107134
108135/**
109136 * @summary Capture a log with the `info` level. Requires `_experiments.enableLogs` to be enabled.
110137 *
111138 * @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' } .
113140 *
114141 * @example
115142 *
116143 * ```
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+ * });
118159 * ```
119160 */
120- export function info ( message : string , attributes ?: Log [ 'attributes' ] ) : void {
161+ export function info ( message : ParameterizedString , attributes ?: Log [ 'attributes' ] ) : void {
121162 captureLog ( 'info' , message , attributes ) ;
122163}
123164
124165/**
125166 * @summary Capture a log with the `warn` level. Requires `_experiments.enableLogs` to be enabled.
126167 *
127168 * @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' } .
129170 *
130171 * @example
131172 *
132173 * ```
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+ * });
134190 * ```
135191 */
136- export function warn ( message : string , attributes ?: Log [ 'attributes' ] ) : void {
192+ export function warn ( message : ParameterizedString , attributes ?: Log [ 'attributes' ] ) : void {
137193 captureLog ( 'warn' , message , attributes ) ;
138194}
139195
140196/**
141197 * @summary Capture a log with the `error` level. Requires `_experiments.enableLogs` to be enabled.
142198 *
143199 * @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' } .
145201 *
146202 * @example
147203 *
148204 * ```
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+ * });
150222 * ```
151223 */
152- export function error ( message : string , attributes ?: Log [ 'attributes' ] ) : void {
224+ export function error ( message : ParameterizedString , attributes ?: Log [ 'attributes' ] ) : void {
153225 captureLog ( 'error' , message , attributes ) ;
154226}
155227
156228/**
157229 * @summary Capture a log with the `fatal` level. Requires `_experiments.enableLogs` to be enabled.
158230 *
159231 * @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' } .
161233 *
162234 * @example
163235 *
164236 * ```
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+ * });
166254 * ```
167255 */
168- export function fatal ( message : string , attributes ?: Log [ 'attributes' ] ) : void {
256+ export function fatal ( message : ParameterizedString , attributes ?: Log [ 'attributes' ] ) : void {
169257 captureLog ( 'fatal' , message , attributes ) ;
170258}
171259
172260/**
173261 * @summary Capture a log with the `critical` level. Requires `_experiments.enableLogs` to be enabled.
174262 *
175263 * @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' } .
177265 *
178266 * @example
179267 *
180268 * ```
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+ * });
182286 * ```
183287 */
184- export function critical ( message : string , attributes ?: Log [ 'attributes' ] ) : void {
288+ export function critical ( message : ParameterizedString , attributes ?: Log [ 'attributes' ] ) : void {
185289 captureLog ( 'critical' , message , attributes ) ;
186290}
291+
292+ export { fmt } from '@sentry/core' ;
0 commit comments