Created
June 11, 2014 08:17
-
-
Save hyzhak/2c88743a11afc8932917 to your computer and use it in GitHub Desktop.
how to setup Winston logger by nconf
This file contains hidden or 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
| /** | |
| * 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