1.0.4 • Published 5 years ago

@zipdrug/logger v1.0.4

Weekly downloads
-
License
MIT
Repository
github
Last release
5 years ago

logger

CircleCI semantic-release

Installation

npm i --save @zipdrug/logger

Setup

import Logger from '@zipdrug/logger';
import { ENVIRONMENT, LOG_LEVEL, LOG_EVENTS, DATADOG_API_KEY } from './Settings';

const Log = new Logger({
  appName: 'phone-api',
  datadogApiKey: DATADOG_API_KEY,
  level: LOG_LEVEL,
  logEvents: LOG_EVENTS === 'true',
  logToCloudwatch: ['production', 'staging'].indexOf(ENVIRONMENT) > -1,
  mock: ENVIRONMENT === 'test',
});

Constructor Options

  • appName: Events sent to Datadog will have app:appName tag added.
  • datadogApiKey: Log.event will send the event to Datadog if set.
  • level: The logging level. Defaults to "info".
  • logEvents: Pass through Log.event calls to Log.info. Default is true.
  • logToCloudwatch: Add the Cloudwatch transport?. Default is false.
  • mock: Set to true to not log anything or send any events. Useful in test env.

API

// These pass through to Winston
// https://www.npmjs.com/package/winston#using-logging-levels
Log.error();
Log.warn();
Log.info();
Log.verbose();
Log.debug();
Log.silly();

// This either passes through to Log.info or sends to Datadog, or both,
// depending on your options.
Log.event();

Log.event object properties

  • aggregation_key: Any string to group events by, such as a transaction ID
  • data: An object with any properties you need in the event to help know what happened. These are converted into Datadog tags, so they should be things like IDs and short strings.
  • name: The event name. Any identifying string. This becomes the event title in Datadog.
  • message: An optional longer message for the event. This becomes the event text in Datadog.
  • type: The event type, similar to a logging level. You can import { EventType } from this package to get an enum for this. The default is EventType.Info.

Log.event example

import { EventType } from '@zipdrug/logger';

Log.event({
  aggregation_key: call_id,
  data: {
    ...opts,
  },
  message: e.message,
  name: 'failedCallingPharmacyPhones',
  type: EventType.Error,
});
1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago

0.0.1

6 years ago