Skip to content

Instantly share code, notes, and snippets.

@GuillermoPena
Created May 28, 2014 09:53
Show Gist options
  • Save GuillermoPena/064d0a71470b81ffe040 to your computer and use it in GitHub Desktop.
Save GuillermoPena/064d0a71470b81ffe040 to your computer and use it in GitHub Desktop.
NodeJS - WINSTON : Logging with winston
// More info here: https://github.com/flatiron/winston
// Simple Example
var winston = require('winston')
var mongoTransport = require('winston-mongodb').MongoDB
var defaultLogger = winston
defaultLogger.level = 'silly'
defaultLogger.silly("Default logger")
// Complex Example
var logger = new winston.Logger({
transports: [
new winston.transports.Console({ level: 'debug', colorize: true }),
new winston.transports.File({ filename: 'winston.log', json: false }),
new mongoTransport({ db: 'winston' }) // Default ({ collection: 'log', host: 'localhost', port: 27017})
//new winston.transports.Redis() // Default: ({ host: 'localhost', port: 6379, auth: 'None' })
],
colors: [{
info: 'blue',
warn: 'yellow',
error: 'red'
}]
})
logger.info(logger.levels)
logger.info("Hello", { metadata: "metadata" })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment