Use woodlot as ExpressJS middleware
masterThe middlewareLogger can be integrated into your ExpressJS middleware chain to log all incoming HTTP requests. It supports various configurations for file streams, route whitelisting, user analytics, and output formats like json, common, or combined (Apache formats).
Important Note: To log request body or cookies in json format, you must enable bodyParser and cookieParser middlewares in Express before adding the woodlot middleware.
var express = require('express');
var app = express();
var woodlot = require('woodlot').middlewareLogger;
app.use(
woodlot({
streams: ['./logs/app.log'],
stdout: false,
routes: {
whitelist: ['/api', '/dashboard'],
strictChecking: false
},
userAnalytics: {
platform: true,
country: true
},
format: {
type: 'json',
options: {
cookies: true,
headers: true,
spacing: 4,
separator: '\n'
}
}
})
);