Created
September 6, 2017 13:44
-
-
Save 92bondstreet/99b9acadef08415fe25ac5a22b8c158c to your computer and use it in GitHub Desktop.
winston logs to elasticsearch
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
| const winston = require('winston'); | |
| const Elasticsearch = require('winston-elasticsearch'); | |
| const esTransportOpts = () => { | |
| return { | |
| 'indexPrefix': 'fifa', | |
| 'level': 'debug' | |
| }; | |
| }; | |
| winston.add(winston.transports.Elasticsearch, esTransportOpts); | |
| /** | |
| * Colorized logger | |
| * | |
| * @return {Logger} | |
| */ | |
| const logger = new winston.Logger({ | |
| 'transports': [ | |
| new winston.transports.Console({ | |
| 'colorize': 'all', | |
| 'level': 'debug', | |
| 'timestamp': true | |
| }), | |
| new Elasticsearch(esTransportOpts()) | |
| ] | |
| }); | |
| logger.rewriters.push((level, msg, meta) => { | |
| Object.assign(meta, { | |
| 'app': 'awesome' | |
| }); | |
| return meta; | |
| }); | |
| logger.debug('test of debug'); | |
| logger.error('test of error'); | |
| logger.info('nothing'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment