Created
October 5, 2018 14:05
-
-
Save nikolayvitaev/a5ff0387fed18b82be8b576086ff0572 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
const winston = require('winston'); | |
// | |
// Or use `Symbol.for` instead of `triple-beam`: | |
// - const LEVEL = Symbol.for('level'); | |
// - const MESSAGE = Symbol.for('message'); | |
// | |
const { LEVEL, MESSAGE } = require('triple-beam'); | |
const logger = winston.createLogger({ | |
transports: [ | |
new winston.transports.Console({ | |
// | |
// Possible to override the log method of the | |
// internal transports of [email protected]. | |
// | |
log(info, callback) { | |
setImmediate(() => this.emit('logged', info)); | |
if (this.stderrLevels[info[LEVEL]]) { | |
console.error(info[MESSAGE]); | |
if (callback) { | |
callback(); | |
} | |
return; | |
} | |
console.log(info[MESSAGE]); | |
if (callback) { | |
callback(); | |
} | |
} | |
}) | |
] | |
}); | |
logger.log({ | |
level: 'info', | |
message: 'foo' | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment