To log response body with Node Express, we use express-winston
.
For instance, we write
expressWinston.requestWhitelist.push("body");
expressWinston.responseWhitelist.push("body");
app.use(
expressWinston.logger({
transports: [
new winston.transports.Console({
json: true,
colorize: true,
}),
],
meta: true,
msg: "HTTP {{req.method}} {{req.url}}",
expressFormat: true,
colorStatus: true,
ignoreRoute: (req, res) => {
return false;
},
})
);
to add a logger with expressWinston.logger
.
The meta
option lets us set whether to log meta data.
msg
is the log entry format.
expressFormat
lets us set whether to use the default formatting.
colorStatus
lets us set whether to color the log entry.
ignoreRoute
lets us set the routes to skip logging for.