Skip to content

Instantly share code, notes, and snippets.

@deleteman
Created July 29, 2019 21:04
Show Gist options
  • Save deleteman/f46a5b63937710629dcffdd51b34aede to your computer and use it in GitHub Desktop.
Save deleteman/f46a5b63937710629dcffdd51b34aede to your computer and use it in GitHub Desktop.
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