This package has been deprecated

Author message:

Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

winston-datadog-logger
TypeScript icon, indicating that this package has built-in type declarations

4.0.1 • Public • Published

code style: prettier Build Status

Winston Datadog Logger

A winston logger with datadog support.

How to install

$ npm i winston-datadog-logger

Transport

The library exposes the transport itself.
You can initialize a transport with the following options:

const options: IDogapiTransportOptions = {
   apiKey: null, // string. The datadog api key of your application
   appKey: null, // string. The datadog app key of your application
   handleExceptions: true, // boolean. It defaults to `true`
   level: 'debug', // (optional) WinstonLevel. Defaults to `debug`. Possible values `error`, `warning`, `info`, `verbose`, `debug`, `silly`
   logDatadogEvents: true, // boolean. It defaults to `true`
   silent: true, // boolean. It defaults to `true`
   tags: ['environment:production', 'version:1.2.3'], // allows transport level tagging in datadog
   title: 'test-title' // string. It defaults to empty and can be overridden in the log messages
}

Logger

The library provides a Logger instance.

The LoggerOptions (The options for initializing the logger)

The WinstonEvent enum that exposes the available event levels for your logs.

import { Logger, 
         LoggerOptions, 
         WinstonEvent } from 'winston-datadog-logger';
 
// Initializing the options. 
const options = {
  exitOnError: false, // boolean. It defaults to `false`
  environment: null, // (optional) string. It defaults to `null`
  instance: null, // (Optional) string. It defaults to `null`
  eventMapping: { // (Optional) The mapping of Winston events to Datadog ones. Possible values: `info`, `error`, `warning`, `success`
    debug: 'info',
    error: 'error',
    info: 'info',
    silly: 'info',
    verbose: 'info',
    warn: 'warning',
  },
  logToConsole: false, // (optional) boolean. It defaults to `null`
  consoleTransportOptions: {
    level: 'debug', // (optional) WinstonLevel. Defaults to `debug`. Possible values `error`, `warning`, `info`, `verbose`, `debug`, `silly`
    silent: true, // (optional) boolean. It defaults to `true`
    handleExceptions: true // (optional) boolean. It defaults to `true`
  },
  datadogLoggerEnabled: true, // (optional) boolean. It defaults to `true`
  dogapiTransportOptions: {
    apiKey: null, // string. The datadog api key of your application
    appKey: null, // string. The datadog app key of your application
    handleExceptions: true, // boolean. It defaults to `true`
    level: 'debug', // (optional) WinstonLevel. Defaults to `debug`. Possible values `error`, `warning`, `info`, `verbose`, `debug`, `silly`
    logDatadogEvents: true, // boolean. It defaults to `true`
    tags: ['environment:production', 'version:1.2.3'], // allows transport level tagging in datadog
    title: 'test-title' // string. It defaults to empty and can be overridden in the log messages
  }
};
 
// Initializing the Logger using the options
Logger.initialize(options);
 
 
// Use the logger like this
// Logger.log({ level }, { message }, { meta });
 
// e.g
Logger.log(WinstonEvent.Debug, 'example message', {'title': 'your-title'});

Additionally, the library provides a Transport instance if composing your own logger. This is consumed similarly to the logger, albeit with fewer options

import * as winston from 'winston';
import { Transport as DatadogTransport } from 'winston-datadog-logger';
 
const options = { /* same as above */ };
 
const logger = winston.createLogger({
  transports: [DatadogTransport(
    options.dogapiTransportOptions,
    options,
  )],
});
 
logger.log('debug', 'example message', { 'title': 'your-title' });

The second argument is optional, merely an escape hatch for any overrides from the larger logger options above.

Dependencies (4)

Dev Dependencies (7)

Package Sidebar

Install

npm i winston-datadog-logger

Weekly Downloads

169

Version

4.0.1

License

MIT

Unpacked Size

54.5 kB

Total Files

61

Last publish

Collaborators

  • kioannou