@financial-times/n-logger
N-logger is a Winston wrapper which sends logs to Splunk's Http Event Collector (HEC).
Last updated 5 months ago by the-ft .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @financial-times/n-logger 
SYNC missed versions from official npm registry.

Next Logger Circle CI GitHub release

N-logger is a Winston wrapper which sends logs to Splunk's Http Event Collector (HEC).

N-logger is not only used by Next. Please be mindful of this as any changes may impact other teams, such as Internal Products, differently.

Installation

npm install @financial-times/n-logger

Ensure SPLUNK_HEC_TOKEN is in the app's shared folder in Vault.

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' });
logger.info({ event: 'UPDATE_NOTIFICATION', data: data });

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 following loggers are added:

  • The console logger

    • logger level can be set by CONSOLE_LOG_LEVEL env var (defaults to silly).
  • The splunkHEC logger, if SPLUNK_HEC_TOKEN is present

    • logger level can be set by SPLUNK_LOG_LEVEL env var (defaults to warn).

If you wish to see logs in Splunk that are at levels lower than warn, you can change the default level by setting a SPLUNK_LOG_LEVEL environment variable.

Testing n-logger locally

If you are making a change to n-logger it is worth testing it locally to check it is sending logs successfully before merging.

  1. Create a test.js file in the root of your local n-logger.
  2. Add the following to this file:
const logger = require('./dist/main').default;
require('isomorphic-fetch');

logger.warn('Testing Testing Testing');
logger.warn({ event: 'HELLO_WORLD', message: 'Testing 1 2 3', count: 5 }, {fizz: 'buzz'});
  1. In the terminal export NODE_ENV=production, export SYSTEM_CODE=next-foo-bar and export SPLUNK_HEC_TOKEN={token} (find this token in the next/shared folder in Vault).

  2. Run node test in the terminal.

  3. If everything is working correctly, you should be able to see your test logs in Splunk with the query index=heroku source="/var/log/apps/heroku/ft-next-foo-bar.log".

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
  • IMPORTANT NOTE - do not send errors as properties of other objects, e.g. {event: 'My_EVENT', error}. This will result in no details of the error being logged**

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

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

removeConsole()

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

removeSplunkHEC()

clearLoggers()

addContext(meta)

meta to be sent with every subsequent log call

logger

The Winston object

Current Tags

  • 6.1.1                                ...           latest (5 months ago)

43 Versions

  • 6.1.1                                ...           5 months ago
  • 6.1.0                                ...           2 years ago
  • 6.0.3                                ...           2 years ago
  • 6.0.2                                ...           2 years ago
  • 6.0.1                                ...           2 years ago
  • 6.0.0                                ...           2 years ago
  • 5.7.2                                ...           2 years ago
  • 5.7.1                                ...           2 years ago
  • 5.7.0                                ...           2 years ago
  • 5.6.5                                ...           2 years ago
  • 5.6.4                                ...           2 years ago
  • 5.6.3                                ...           2 years ago
  • 5.6.2                                ...           2 years ago
  • 5.6.1                                ...           2 years ago
  • 5.6.0                                ...           2 years ago
  • 5.6.0-beta.2                                ...           2 years ago
  • 5.6.0-beta.1                                ...           2 years ago
  • 5.5.11                                ...           2 years ago
  • 5.5.10                                ...           2 years ago
  • 5.5.9                                ...           2 years ago
  • 0.0.0                                ...           2 years ago
  • 5.5.8                                ...           2 years ago
  • 5.5.7                                ...           3 years ago
  • 5.5.6                                ...           3 years ago
  • 5.5.4                                ...           3 years ago
  • 5.5.3                                ...           3 years ago
  • 5.5.2                                ...           3 years ago
  • 5.5.1                                ...           3 years ago
  • 5.5.0                                ...           3 years ago
  • 5.4.8                                ...           3 years ago
  • 5.4.7                                ...           4 years ago
  • 5.4.6                                ...           4 years ago
  • 5.4.5                                ...           4 years ago
  • 5.4.4                                ...           4 years ago
  • 5.4.3                                ...           4 years ago
  • 5.4.0                                ...           4 years ago
  • 5.3.0                                ...           4 years ago
  • 5.2.0                                ...           4 years ago
  • 5.1.1                                ...           4 years ago
  • 5.1.0                                ...           4 years ago
  • 5.0.2                                ...           4 years ago
  • 5.0.1                                ...           4 years ago
  • 5.0.0                                ...           4 years ago
Downloads
Today 0
This Week 0
This Month 48
Last Day 0
Last Week 44
Last Month 6
Dependencies (4)
Dev Dependencies (12)
Dependents (55)

Copyright 2014 - 2017 © taobao.org |