const Transport = require('winston-transport'); const moment = require('moment'); const chalk = require('chalk'); const Constants = { Colors: { error: 'red', warn: 'yellow', info: 'blue', verbose: 'cyan', debug: 'magenta', silly: 'magentaBright' } }; class ExtendedConsole extends Transport { constructor(opts) { super(opts); // // Consume any custom options here. e.g.: // - Connection information for databases // - Authentication information for APIs (e.g. loggly, papertrail, // logentries, etc.). // } log(info, callback) { setImmediate(() => { this.emit('logged', info); }); //console.log('Extended console:'); //console.log(info); const hdr = info.message.match(/^(\[[0-9\-: ]{19}\](\[shard-[0-9]{2}\])?)/); if(hdr) info.message = info.message.replace(hdr[1], '').trim(); const color = Constants.Colors[info.level]; const header = `${chalk[color](hdr ? hdr[1] : `[${this.date}]`)}`; console.log(`${header} ${info.message}`); if (callback) { callback(); // eslint-disable-line callback-return } } get date() { return moment().format("MM-DD-YYYY hh:mm:ss"); } } module.exports = ExtendedConsole;