JSPM

  • Created
  • Published
  • Downloads 2822
  • Score
    100M100P100Q19752F
  • License MIT

Package Exports

  • @financial-times/n-logger

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@financial-times/n-logger) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Next Logger Circle CI

Logging utility

Installation

npm install @financial-times/n-logger

Usage

import logger from '@financial-times/n-logger';

logger.log('info', 'Saying hello');
logger.info('Saying hello');
logger.warn('Everything’s mostly cool');
logger.error('Uh-oh', { field: 'some value' });

const err = new Error('Whoops!');
logger.error('Uh-oh', err, { extra_field: 'boo' });

If using CommonJS modules

const logger = require('@financial-times/n-logger').default;

Loggers

By default

  • the console logger is added
    • logger level can be set by CONSOLE_LOG_LEVEL env variable; defaults to silly
  • the splunk logger is added if NODE_ENV === production
    • logger level can be set by SPLUNK_LOG_LEVEL env variable; defaults to warn
  • the splunkHEC logger is added if NODE_ENV === production && SPLUNK_HEC_TOKEN
    • logger level can be set by SPLUNK_LOG_LEVEL env variable; defaults to warn

API

log(level, message, ...meta)

  • level can be silly, debug, verbose, info, warn or error
  • message is optional
  • any number of meta objects can be supplied, including Error objects

silly|debug|verbose|info|warn|error(message, ...meta)

addConsole(level = 'info', opts = {})

removeConsole()

addSplunk(splunkUrl, level = 'info', opts = {})

removeSplunk()

addSplunkHEC(level = 'info', opts = {})

removeSplunkHEC()

clearLoggers()

addContext(meta)

meta to be sent with every subsequent log call

logger

The Winston object