1.0.4 • Published 6 years ago
@zipdrug/logger v1.0.4
logger
Installation
npm i --save @zipdrug/loggerSetup
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 haveapp:appNametag added.datadogApiKey:Log.eventwill send the event to Datadog if set.level: The logging level. Defaults to "info".logEvents: Pass throughLog.eventcalls toLog.info. Default istrue.logToCloudwatch: Add the Cloudwatch transport?. Default isfalse.mock: Set totrueto 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 IDdata: 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 eventtitlein Datadog.message: An optional longer message for the event. This becomes the eventtextin 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 isEventType.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,
});