Created
July 29, 2019 21:04
-
-
Save deleteman/f46a5b63937710629dcffdd51b34aede to your computer and use it in GitHub Desktop.
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 = { | |
level: 'info' | |
}; | |
const logger = winston.createLogger({ | |
level: 'info', | |
format: winston.format.json(), | |
transports: [ | |
new winston.transports.File({ filename: "logfile.log", level: 'error' }), //save errors on file | |
new Elasticsearch(esTransportOpts) //everything info and above goes to elastic | |
] | |
}); | |
if (process.env.NODE_ENV !== 'production') { | |
logger.add(new winston.transports.Console({ //we also log to console if we're not in production | |
format: winston.format.simple() | |
})); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment