1.0.26 • Published 2 years ago

winston-sentry-log v1.0.26

Weekly downloads
4,518
License
MIT
Repository
github
Last release
2 years ago

winston-sentry-log

Sentry transport for the winston v3 logger using @sentry/node.

Index

Install

yarn add winston winston-sentry-log

Usage

You can configure winston-sentry-log in two different ways.

With winston.createLogger:

import winston from 'winston';
import Sentry from 'winston-sentry-log';

const options = {
  config: {
    dsn: "https://******@sentry.io/12345"
  },
  level: "info"
};

const logger = winston.createLogger({
  transports: [new Sentry(options)]
});

Or with winston's add method:

import winston from 'winston';
import Sentry from 'winston-sentry-log';

const logger = winston.createLogger();

logger.add(Sentry, options);

See Options below for custom configuration.

Options (options)

Per options variable above, here are the default options provided:

Default Sentry options:

  • dsn (String) - your Sentry DSN or Data Source Name (defaults to process.env.SENTRY_DSN)

Transport related options:

  • name (String) - transport's name (defaults to winston-sentry-log)
  • silent (Boolean) - suppress logging (defaults to false)
  • level (String) - transport's level of messages to log (defaults to info)
  • levelsMap (Object) - log level mapping to Sentry (see Log Level Mapping below)
  • sentryClient (Sentry) - the custom sentry client (defaults to require('@sentry/node'))
  • isClientInitialized (boolean) - whether to initialize the provided sentry client or not (defaults to false)
    • If isClientInitialized is set to true, a custom sentryClient initialized must provided, otherwise internal sentryClient will not initialized

Default Sentry Options (options.config)

  • logger (String) - defaults to winston-sentry-log
  • server_name (String) - defaults to process.env.SENTRY_NAME or os.hostname()
  • release (String) - defaults to process.env.SENTRY_RELEASE
  • environment (String) - defaults to process.env.SENTRY_ENVIRONMENT)
  • modules (Object) - defaults to package.json dependencies
  • extra (Object) - no default value
  • fingerprint (Array) - no default value

For a full list of Sentry options, please visit https://docs.sentry.io/clients/node/config/.

Log Level Mapping

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.

License

MIT License

1.0.26

2 years ago

1.0.25

2 years ago

1.0.24

3 years ago

1.0.23

3 years ago

1.0.22

3 years ago

1.0.21

3 years ago

1.0.20

3 years ago

1.0.19

4 years ago

1.0.18

4 years ago

1.0.17

4 years ago

1.0.16

4 years ago

1.0.15

4 years ago

1.0.14

4 years ago

1.0.13

4 years ago

1.0.11

5 years ago

1.0.10

5 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago