UNPKG

895 BJavaScriptView Raw
1const { createLogger, format, transports } = require('winston');
2const chalk = require('chalk').default;
3const { combine, colorize, label, printf, splat, timestamp } = format;
4
5const logFormat = (loggerLabel) => combine(
6 timestamp(),
7 splat(),
8 colorize(),
9 label({ label: loggerLabel }),
10 printf(info => `${info.timestamp} ${chalk.cyan(info.label)} ${info.level}: ${info.message}`)
11);
12
13const createLoggerWithLabel = (label) => createLogger({
14 level: process.env.LOG_LEVEL || 'info',
15 transports: [new transports.Console({})],
16 format: logFormat(label)
17});
18
19module.exports = {
20 gateway: createLoggerWithLabel('[EG:gateway]'),
21 policy: createLoggerWithLabel('[EG:policy]'),
22 config: createLoggerWithLabel('[EG:config]'),
23 db: createLoggerWithLabel('[EG:db]'),
24 admin: createLoggerWithLabel('[EG:admin]'),
25 plugins: createLoggerWithLabel('[EG:plugins]'),
26 createLoggerWithLabel
27};