Adding HTTP logging with Morgan

In the previous section, we managed to provide a very basic HTTP logging feature when we included some middleware that did Winston logging:

app.use((req, res, next) => {
logger.info(`${req.method} request for ${req.originalUrl}`);
next();
});

While this worked, there is much more information that we could desire, such as the HTTP status code for the response, the processing time it required, and more, so let's add Morgan into the mix, since that package is specific for requests logging.

You can learn more about Morgan at https://github.com/expressjs/morgan.

In this recipe, we'll add Morgan to our software stack so that we can get better logs for all the processed requests.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.116.21.239