Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion includes/logs/javascript-winston-integration.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,43 @@ 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, {
// Only capture error and warn logs
levels: ["error", "warn"],
});
```

### Custom Level Mapping

<AvailableSince version="10.37.0" />

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`).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

l: Do you know if we have a page somewhere where these are listed in the docs? If so would probably be better to point there in case we add more levels in the future

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very good point. It is documented: https://docs.sentry.io/platforms/javascript/guides/nextjs/logs/#log-levels

I'll update it

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok never mind, these log levels are for nextjs.

In a follow up I will make the logs description a little better and make i a single source of truth.


```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()],
});
```