Skip to content

Instantly share code, notes, and snippets.

@92bondstreet
Created September 6, 2017 13:44
Show Gist options
  • Select an option

  • Save 92bondstreet/99b9acadef08415fe25ac5a22b8c158c to your computer and use it in GitHub Desktop.

Select an option

Save 92bondstreet/99b9acadef08415fe25ac5a22b8c158c to your computer and use it in GitHub Desktop.
winston logs to elasticsearch
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