Skip to content

Instantly share code, notes, and snippets.

@sht5
Created June 28, 2017 17:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sht5/8b6a2e3bf5e5b07bfe1373d502adab42 to your computer and use it in GitHub Desktop.
Save sht5/8b6a2e3bf5e5b07bfe1373d502adab42 to your computer and use it in GitHub Desktop.
winston-logzio integration with winston in nodejs
/**
* Created by shahartaite on 12/09/2016.
*/
const winston = require('winston');
const logzioWinstonTransport = require('winston-logzio');
const loggerOptions = {
token: 'YOUR_TOKEN',
host: 'listener.logz.io',
type: 'nodejs' // if you integrate any other services with logz.io such
// as your clientside logs you can differentiate using this property
};
winston.emitErrs = true;
const logger = new winston.Logger({
transports: [
new winston.transports.File({ // example of a normal transport for winston writing logs to file
level: 'error',
filename: 'mylogs.txt',
handleExceptions: true,
json: false,
maxsize: 5242880, //5MB
maxFiles: 5,
colorize: true,
}),
new winston.transports.Console({ // example of a normal transport for winston writing logs to console
level: 'debug',
handleExceptions: true,
json: false,
colorize: true,
prettyPrint: true,
}),
],
exitOnError: false
});
const env = process.env.NODE_ENV || 'dev'; // these next couple of lines make sure you don't
//send logs to logz.io whilst in development mode
if(env === 'production') {
logger.add(logzioWinstonTransport, loggerOptions); // add another transport with the logz.io configuration from the top
}
module.exports = logger;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment