Skip to content

Instantly share code, notes, and snippets.

@farukcam
Forked from sht5/logger.js
Created October 3, 2018 12:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save farukcam/d2821d053d75aba9a936f2ea4a34b4d7 to your computer and use it in GitHub Desktop.
Save farukcam/d2821d053d75aba9a936f2ea4a34b4d7 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