Last active
December 10, 2015 21:29
-
-
Save 8bitDesigner/4495287 to your computer and use it in GitHub Desktop.
Drop in replacement for `console` logging in a NodeJS application
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
var console = require(__dirname + '/logger') | |
// All three of these do the same thing | |
console.log(1, 2, 3) // Gets rewritten as console.log('info', 1, 2, 3) | |
console.log('info', 1, 2, 3) // Indentical as below | |
console.info(1, 2, 3) | |
// Works as well | |
console.warn('oh noes') | |
console.error('oh poop!') |
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
winston = require "winston" | |
options = | |
timestamp: true | |
colorize: true | |
# Re-configure console transport | |
winston.remove winston.transports.Console | |
winston.add winston.transports.Console, options | |
winston.setLevels winston.config.syslog.levels | |
# Default log level to info | |
winston.oldlog = winston.log | |
winston.log = (args...) -> | |
args.unshift 'info' if args[0] not in Object.keys(winston.config.syslog.levels) | |
winston.oldlog.apply winston, args | |
module.exports = winston |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment