Skip to content

Instantly share code, notes, and snippets.

@ghost23
Created June 14, 2017 07:30
Show Gist options
  • Save ghost23/96d241d3cebae0898627f67b56dca505 to your computer and use it in GitHub Desktop.
Save ghost23/96d241d3cebae0898627f67b56dca505 to your computer and use it in GitHub Desktop.
Simple Browser (console) logging transport for winston
import util from 'util';
import winston from 'winston';
const BrowserLogger = function (options) {
this.name = 'browserLogger';
this.level = options.level || 'info';
};
winston.transports.BrowserLogger = BrowserLogger;
util.inherits(BrowserLogger, winston.Transport);
BrowserLogger.prototype.log = function(level, msg, meta, callback) {
if(level === "error") {
console.error(msg, meta);
} else if (level === "warn") {
console.warn(msg, meta);
} else {
console.log(msg, meta);
}
callback(null, true);
};
export default BrowserLogger;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment