Skip to content

Instantly share code, notes, and snippets.

@hyzhak
Created June 11, 2014 08:17
Show Gist options
  • Select an option

  • Save hyzhak/2c88743a11afc8932917 to your computer and use it in GitHub Desktop.

Select an option

Save hyzhak/2c88743a11afc8932917 to your computer and use it in GitHub Desktop.
how to setup Winston logger by nconf
/**
* Setup multiple winston logger:
* https://github.com/flatiron/winston#working-with-multiple-loggers-in-winston
*
* by nconf:
* https://github.com/flatiron/nconf
*/
var winston = require('winston'),
nconf = require('nconf');
var config = nconf.argv()
.env()
.file({ file: 'scripts/config/local_settings.json' })
.file({ file: 'scripts/config/global_settings.json' });
var loggerConfig = config.get('logger');
Object.keys(loggerConfig).forEach(function(key) {
winston.loggers.add(key, loggerConfig[key]);
});
/**
* global_settings.json
*/
{
"logger": {
"db": {
"console": {
"level": "info",
"colorize": true,
"label": "db"
}
},
"express": {
"console": {
"level": "info",
"colorize": true,
"label": "express"
}
},
"passport": {
"console": {
"level": "info",
"colorize": "true",
"label": "passport"
}
}
}
}
/**
* usage
*/
var logger = require('winston').loggers.get('express');
logger.info('hello world!');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment