Created
June 14, 2017 07:30
-
-
Save ghost23/96d241d3cebae0898627f67b56dca505 to your computer and use it in GitHub Desktop.
Simple Browser (console) logging transport for winston
This file contains 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
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