winston-sentry-javascript-node
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.
Installation
npm install winston-sentry-javascript-node --save
Usage
import { SentryTransport } from 'winston-sentry-javascript-node';
const logger = winston.createLogger({
transports: [
new SentryTransport({
dsn: 'MY_SENTRY_DSN',
}),
],
});
logger.error('Plain text error.');
logger.error(new Error('Something went wrong.'));
Set user information, as well as tags and further extras.
logger.error('Plain text error.', {
extra: {
foo: 'bar',
},
tags: {
foo: 'bar',
},
user: {
ip: '127.0.0.1',
username: 'user1',
},
});
Handle Exception
Catch and send uncaughtException
to the Sentry.
const logger = winston.createLogger({
transports: [
new SentryTransport({
dsn: 'MY_SENTRY_DSN',
handleExceptions: true,
}),
],
});
const logger = winston.createLogger({
exceptionHandlers: [
new SentryTransport({
dsn: 'MY_SENTRY_DSN',
}),
]
});
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