UNPKG

express-gateway

Version:

A microservices API gateway built on top of ExpressJS

28 lines (24 loc) 895 B
const { createLogger, format, transports } = require('winston'); const chalk = require('chalk').default; const { combine, colorize, label, printf, splat, timestamp } = format; const logFormat = (loggerLabel) => combine( timestamp(), splat(), colorize(), label({ label: loggerLabel }), printf(info => `${info.timestamp} ${chalk.cyan(info.label)} ${info.level}: ${info.message}`) ); const createLoggerWithLabel = (label) => createLogger({ level: process.env.LOG_LEVEL || 'info', transports: [new transports.Console({})], format: logFormat(label) }); module.exports = { gateway: createLoggerWithLabel('[EG:gateway]'), policy: createLoggerWithLabel('[EG:policy]'), config: createLoggerWithLabel('[EG:config]'), db: createLoggerWithLabel('[EG:db]'), admin: createLoggerWithLabel('[EG:admin]'), plugins: createLoggerWithLabel('[EG:plugins]'), createLoggerWithLabel };