From dbb5797131f40809fd8799fbf168ac3f3d0120ee Mon Sep 17 00:00:00 2001 From: JPeer264 Date: Wed, 28 Jan 2026 13:35:45 +0100 Subject: [PATCH] feat(winston): Add new option for winston transport --- .../logs/javascript-winston-integration.mdx | 34 ++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/includes/logs/javascript-winston-integration.mdx b/includes/logs/javascript-winston-integration.mdx index f02b2af18b27d..6f288755b6ebe 100644 --- a/includes/logs/javascript-winston-integration.mdx +++ b/includes/logs/javascript-winston-integration.mdx @@ -13,7 +13,11 @@ const logger = winston.createLogger({ }); ``` -The `createSentryWinstonTransport` method accepts a `levels` option, which allows you to filter which levels are sent to Sentry. By default all levels are logged. +The `createSentryWinstonTransport` method accepts the following options: + +### Filtering Log Levels + +Use the `levels` option to filter which levels are sent to Sentry. By default all levels are logged. ```js const SentryWinstonTransport = Sentry.createSentryWinstonTransport(Transport, { @@ -21,3 +25,31 @@ const SentryWinstonTransport = Sentry.createSentryWinstonTransport(Transport, { levels: ["error", "warn"], }); ``` + +### Custom Level Mapping + + + +If you use [custom winston log levels](https://github.com/winstonjs/winston?tab=readme-ov-file#using-custom-logging-levels), they won't be sent to Sentry by default because they can't be mapped to Sentry's severity levels. Use the `customLevelMap` option to map your custom levels to Sentry levels (`fatal`, `error`, `warning`, `info`, `debug`, or `trace`). + +```js +const customLevels = { + levels: { + customCritical: 0, + customNotice: 2, + }, +}; + +const SentryWinstonTransport = Sentry.createSentryWinstonTransport(Transport, { + customLevelMap: { + customCritical: "fatal", + customNotice: "info", + }, +}); + +const logger = winston.createLogger({ + levels: customLevels.levels, + level: "customNotice", + transports: [new SentryWinstonTransport()], +}); +```