| 32 | * @param attributes - Arbitrary structured data that stores information about the log - e.g., userId: 100. |
| 33 | */ |
| 34 | export function captureLog(level: LogSeverityLevel, ...args: CaptureLogArgs): void { |
| 35 | const [messageOrMessageTemplate, paramsOrAttributes, maybeAttributesOrMetadata, maybeMetadata] = args; |
| 36 | if (Array.isArray(paramsOrAttributes)) { |
| 37 | // type-casting here because from the type definitions we know that `maybeAttributesOrMetadata` is an attributes object (or undefined) |
| 38 | const attributes = { ...(maybeAttributesOrMetadata as Log['attributes'] | undefined) }; |
| 39 | attributes['sentry.message.template'] = messageOrMessageTemplate; |
| 40 | paramsOrAttributes.forEach((param, index) => { |
| 41 | attributes[`sentry.message.parameter.${index}`] = param; |
| 42 | }); |
| 43 | const message = format(messageOrMessageTemplate, ...paramsOrAttributes); |
| 44 | _INTERNAL_captureLog({ level, message, attributes }, maybeMetadata?.scope); |
| 45 | } else { |
| 46 | _INTERNAL_captureLog( |
| 47 | { level, message: messageOrMessageTemplate, attributes: paramsOrAttributes }, |
| 48 | // type-casting here because from the type definitions we know that `maybeAttributesOrMetadata` is a metadata object (or undefined) |
| 49 | (maybeAttributesOrMetadata as CaptureLogMetadata | undefined)?.scope ?? maybeMetadata?.scope, |
| 50 | ); |
| 51 | } |
| 52 | } |