javascript - Tracking each request logs in Express JS -
i having web application build on node , express in backend. web site having lot of users logs confusing when try debug of logs(console.log) in case of issues. logs clumsy among different users, there way track logs respect request (request id kinda thing)?
recommend simple log middleware, example https://github.com/villadora/express-bunyan-logger
app.use(require('express-bunyan-logger').errorlogger()); app.use(require('express-bunyan-logger')({ name: 'logger', streams: [{ level: 'info', stream: process.stdout }] })); app.use(require('express-bunyan-logger')({ format: ":remote-address - :user-agent[major] custom logger" }); app.use(require('express-bunyan-logger')(); app.use(function(req, res, next) { req.log.debug('this debug in middleware'); next(); });
you can castumize logger, write difference data file ot stdout.
Comments
Post a Comment