1 | const winston = require('winston');
|
2 | const supportsColor = require('supports-color');
|
3 |
|
4 | const config = winston.config;
|
5 |
|
6 | const colorLevels = {
|
7 | silly: 'white',
|
8 | debug: 'white',
|
9 | verbose: 'white',
|
10 | info: 'white',
|
11 | warn: 'yellow',
|
12 | error: 'red',
|
13 | };
|
14 |
|
15 | winston.addColors(colorLevels);
|
16 |
|
17 | const formatter = function formatter(options) {
|
18 | const body = options.message ? options.message : '';
|
19 | const suffix = (options.meta && Object.keys(options.meta).length
|
20 | ? `\n\t${JSON.stringify(options.meta)}` : '');
|
21 |
|
22 | const fullLog = `${body}${suffix}`;
|
23 | return supportsColor.stdout ? config.colorize(options.level, fullLog) : fullLog;
|
24 | };
|
25 |
|
26 | winston.loggers.add('binaris', {
|
27 | transports: [
|
28 | new (winston.transports.Console)({
|
29 | stringify: true,
|
30 | level: process.env.BINARIS_LOG_LEVEL || 'info',
|
31 | prettyPrint: true,
|
32 | colorize: supportsColor.stdout,
|
33 |
|
34 | formatter,
|
35 | }),
|
36 | ],
|
37 | });
|
38 |
|
39 | module.exports = winston.loggers.get('binaris');
|