Use Woodlot as an HTTP logger 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'
}
}
}));
It generates log output in JSON by default -
{
"responseTime": "4ms",
"method": "GET",
"url": "/api",
"ip": "127.0.01",
"body": {},
"params": {},
"query": {},
"httpVersion": "1.1",
"statusCode": 200,
"timeStamp": "23/Apr/2017:20:46:01 +0000",
"contentType": "text/html; charset=utf-8",
"contentLength": "4",
"userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36",
"referrer": null,
"userAnalytics": {
"browser": "Chrome",
"browserVersion": "60.0.3112.90",
"os": "Mac OS",
"osVersion": "10.11.6",
"country": {
"name": "India",
"isoCode": "IN"
}
},
"headers": {
"host": "localhost:8000",
"connection": "keep-alive",
"accept-encoding": "gzip, deflate, sdch, br",
"accept-language": "en-US,en;q=0.8,la;q=0.6"
},
"cookies": {
"userId": "zasd-167279192-asknbke-0684"
}
}