Sentry transport for the winson logger 3+ and uses the @sentry/node SDK instead of the old Raven.
This package is written in Typescript with the well typing and code quality.
npm install winston-sentry-javascript-node --save
import{SentryTransport}from'winston-sentry-javascript-node';constlogger=winston.createLogger({transports: [newSentryTransport({sentry:{dsn: 'MY_SENTRY_DSN',},}),],});logger.error('Plain text error.');logger.error(newError('Something went wrong.'));Set user information, as well as tags and further extras.
logger.error('Plain text error.',{tags: {foo: 'bar',},user: {ip: '127.0.0.1',username: 'user1',},extra: {extra1: 'extra1',extra2: 'extra2',},});Catch and send uncaughtException to the Sentry.
constlogger=winston.createLogger({transports: [newSentryTransport({sentry{dsn: 'MY_SENTRY_DSN',},handleExceptions: true,}),],});// orconstlogger=winston.createLogger({exceptionHandlers: [newSentryTransport({sentry: {dsn: 'MY_SENTRY_DSN',}}),]});newSentryTransport(opts)- opts: TransportStreamOptions
interfaceTransportStreamOptions{format?: logform.Format;level?: string;silent?: boolean;handleExceptions?: boolean;log?(info: any,next: ()=>void): any;logv?(info: any,next: ()=>void): any;close?(): void;}- opts.sentry: Please see Sentry client options.
By default, if you provide an Error Object to logger, this package will set the following extra:
{stack: err.stack,message: err.message,}© Ben Hu (benjamin658), 2019-NOW
Released under the MIT License