-
-
Save farukcam/d2821d053d75aba9a936f2ea4a34b4d7 to your computer and use it in GitHub Desktop.
winston-logzio integration with winston in nodejs
This file contains 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
/** | |
* 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