forked from Galactic/galactic-bot
console transport extension
This commit is contained in:
parent
35459651ca
commit
5450469f3a
56
middleware/logger/transports/ExtendedConsole.js
Normal file
56
middleware/logger/transports/ExtendedConsole.js
Normal file
@ -0,0 +1,56 @@
|
||||
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;
|
Loading…
Reference in New Issue
Block a user