1 | # Next Logger [![Circle CI](https://circleci.com/gh/Financial-Times/n-logger.svg?style=svg)](https://circleci.com/gh/Financial-Times/n-logger)
|
2 |
|
3 | Logging utility
|
4 |
|
5 | ## Installation
|
6 |
|
7 | npm install @financial-times/n-logger
|
8 |
|
9 |
|
10 | ## Usage
|
11 |
|
12 | import logger from '@financial-times/n-logger';
|
13 |
|
14 | logger.log('info', 'Saying hello');
|
15 | logger.info('Saying hello');
|
16 | logger.warn('Everything’s mostly cool');
|
17 | logger.error('Uh-oh', { field: 'some value' });
|
18 |
|
19 | const err = new Error('Whoops!');
|
20 | logger.error('Uh-oh', err, { extra_field: 'boo' });
|
21 |
|
22 | If using CommonJS modules
|
23 |
|
24 | const logger = require('@financial-times/n-logger').default;
|
25 |
|
26 | ### Loggers
|
27 |
|
28 | By default
|
29 |
|
30 | * the `console` logger is added
|
31 | * logger level can be set by `CONSOLE_LOG_LEVEL` env variable; defaults to `silly`
|
32 | * the `splunk` logger is added if `NODE_ENV === production`
|
33 | * logger level can be set by `SPLUNK_LOG_LEVEL` env variable; defaults to `warn`
|
34 | * the `splunkHEC` logger is added if `NODE_ENV === production && SPLUNK_HEC_TOKEN`
|
35 | * logger level can be set by `SPLUNK_LOG_LEVEL` env variable; defaults to `warn`
|
36 |
|
37 | ### API
|
38 |
|
39 | #### log(level, message, ...meta)
|
40 |
|
41 | * `level` can be silly, debug, verbose, info, warn or error
|
42 | * `message` is optional
|
43 | * any number of meta objects can be supplied, including `Error` objects
|
44 |
|
45 | #### silly|debug|verbose|info|warn|error(message, ...meta)
|
46 |
|
47 | #### addConsole(level = 'info', opts = {})
|
48 |
|
49 | #### removeConsole()
|
50 |
|
51 | #### addSplunk(splunkUrl, level = 'info', opts = {})
|
52 |
|
53 | #### removeSplunk()
|
54 |
|
55 | #### addSplunkHEC(level = 'info', opts = {})
|
56 |
|
57 | #### removeSplunkHEC()
|
58 |
|
59 | #### clearLoggers()
|
60 |
|
61 | #### addContext(meta)
|
62 | `meta` to be sent with every subsequent log call
|
63 |
|
64 | #### logger
|
65 |
|
66 | The [Winston object](https://github.com/winstonjs/winston)
|