Raven/Sentry transport for the winston v3 logger.
npm install --save winston winston-sentry-raven-transport
You can configure winston-sentry-raven-transport
in two different ways.
With new winston.Logger
:
const winston = require('winston');
const Sentry = require('winston-sentry-raven-transport');
const options = {
dsn: 'https://******@sentry.io/12345',
level: 'info'
};
const logger = new winston.Logger({
transports: [
new Sentry(options)
]
});
Or with winston's add
method:
const winston = require('winston');
const Sentry = require('winston-sentry-raven-transport');
const logger = new winston.Logger();
logger.add(new Sentry(options));
See Options below for custom configuration.
Per options
variable above, here are the default options provided:
Default Sentry options:
dsn
(String) - your Sentry DSN or Data Source Name (defaults toprocess.env.SENTRY_DSN
)config
(Object) - a Raven configuration object (see Default Raven Options below)install
(Boolean) - automatically catches uncaught exceptions throughRaven.install
if set to true (defaults tofalse
)errorHandler
(Function) - a callback function to use for logging Raven errors (e.g. an invalid DSN key). This defaults to logging theerr.message
, see Default Error Handler below... but if you wish to disable this just passerrorHandler: false
. If there is already anerror
listener then this function will not get bound.raven
(Object) - an optional instance ofRaven
that is already configured viaRaven.config
(if provided this will be used instead of theconfig
option
Transport related options:
name
(String) - transport's name (defaults towinston-sentry-raven
)silent
(Boolean) - suppress logging (defaults tofalse
)level
(String) - transport's level of messages to log (defaults toinfo
)levelsMap
(Object) - log level mapping to Sentry (see Log Level Mapping below)
logger
(String) - defaults towinston-sentry-raven
captureUnhandledRejections
(Boolean) - defaults tofalse
culprit
(String) - defaults to the module or function nameserver_name
(String) - defaults toprocess.env.SENTRY_NAME
oros.hostname()
release
(String) - defaults toprocess.env.SENTRY_RELEASE
tags
(Array or Object) - no default valueenvironment
(String) - defaults toprocess.env.SENTRY_ENVIRONMENT
)modules
(Object) - defaults topackage.json
dependenciesextra
(Object) - no default valuefingerprint
(Array) - no default value
For a full list of Raven options, please visit https://docs.sentry.io/clients/node/config/.
The default error handler is a function that is simply:
function errorHandler(err) {
console.error(err.message);
}
... and it is binded to the event emitter:
Raven.on('error', this.options.errorHandler);
Therefore if you have specified an invalid DSN key, then you will see its output on the command line.
For example:
[email protected] alert: failed to send exception to sentry: HTTP Error (401): Invalid api key
If you pass options.errorHandler: false
then no error handler will be binded.
If you want to log uncaught exceptions with Sentry, then specify install: true
in options:
new Sentry({
install: true
});
If you want to log unhandled promise rejections with Sentry, then specify captureUnhandledRejections: true
in options.config
:
new Sentry({
config: {
captureUnhandledRejections: true
}
});
Winston logging levels are mapped by default to Sentry's acceptable levels.
These defaults are set as `options.levelsMap' and are:
{
silly: 'debug',
verbose: 'debug',
info: 'info',
debug: 'debug',
warn: 'warning',
error: 'error'
}
You can customize how log levels are mapped using the levelsMap
option:
new Sentry({
levelsMap: {
verbose: 'info'
}
});
If no log level mapping was found for the given level
passed, then it will not log anything.