Skip to content

Instantly share code, notes, and snippets.

@nikolayvitaev
Created October 5, 2018 14:05
Show Gist options
  • Save nikolayvitaev/a5ff0387fed18b82be8b576086ff0572 to your computer and use it in GitHub Desktop.
Save nikolayvitaev/a5ff0387fed18b82be8b576086ff0572 to your computer and use it in GitHub Desktop.
'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