You might want to use mongo-morgan-ext
Using:
var logger = require('mongo-morgan-ext'); var db = 'mongodb://localhost:27017/MyDB'; var collection = 'Logs' var skipfunction = function(req, res) { return res.statusCode > 399; }
Expected Result:
{ "RequestID": "", "status": "", "method": "", "Remote-user": "", "Remote-address": "", "URL": "", "HTTPversion": "", "Response-time": "", "date":"", "Referrer": "", "REQUEST": { //10 "Accept": "", "Accept-Charset": "", "Accept-Encoding": "", "Accept-Language": "", "Authorization": "", "Cache-Control": "", "Connection": "", "Cookie": "", "Content-Length": "", "Content-MD5": "", "Content-Type": "", "Expect": "", "Forwarded": "", "From": "", "Host": "", "Max-Forwards": "", "Origin": "", "Pragma": "", "Proxy-Authorization": "", "Range": "", "TE": "", "User-Agent": "", "Via": "", "Warning": "", "Upgrade": "", "Referer": "", "Date": "", "X-requested-with": "", "X-Csrf-Token": "", "X-UIDH": "", "Proxy-Connection": "", "X-Wap-Profile": "", "X-ATT-DeviceId": "", "X-Http-Method-Override":"", "Front-End-Https": "", "X-Forwarded-Proto": "", "X-Forwarded-Host": "", "X-Forwarded-For": "", "DNT": "", "Accept-Datetime": "", "If-Match": "", "If-Modified-Since": "", "If-None-Match": "", "If-Range": "", "If-Unmodified-Since": "" }, "RESPONSE": { "Status": "", "Content-MD5":"", "X-Frame-Options": "", "Accept-Ranges": "", "Age": "", "Allow": "", "Cache-Control": "", "Connection": "", "Content-Disposition": "", "Content-Encoding": "", "Content-Language": "", "Content-Length": "", "Content-Location": "", "Content-Range": "", "Content-Type":"", "Date":"", "Last-Modified": "", "Link": "", "Location": "", "P3P": "", "Pragma": "", "Proxy-Authenticate": "", "Public-Key-Pins": "", "Retry-After": "", "Server": "", "Trailer": "", "Transfer-Encoding": "", "TSV": "", "Upgrade": "", "Vary": "", "Via": "", "Warning": "", "WWW-Authenticate": "", "Expires": "", "Set-Cookie": "", "Strict-Transport-Security": "", "Refresh":"", "Access-Control-Allow-Origin": "", "X-XSS-Protection": "", "X-WebKit-CSP":"", "X-Content-Security-Policy": "", "Content-Security-Policy": "", "X-Content-Type-Options": "", "X-Powered-By": "", "X-UA-Compatible": "", "X-Content-Duration": "", "Upgrade-Insecure-Requests": "", "X-Request-ID": "", "ETag": "", "Accept-Patch": "" } }