simple-express-logs
Simple express logging middleware
Are you prototyping an Express app and want a simple way to log all requests? Good news, you're looking at it.
Install
$ npm install --save simple-express-logs
Usage
const express = ;const logger = ; const app = ;app;
Or, in one line:
app;
Output
By default, simple-express-logs
outputs a timestamp, whether the request was made over HTTP or HTTPS, the HTTP verb, the path, the source IP, and the reverse DNS host (if available.)
20:06 1/15/2019 UTC: https POST /api/items/ from 24.63.26.119
5:17 1/8/2019 UTC: https GET /favicon.ico from 66.249.66.152 (crawl-66-249-66-152.googlebot.com)
20:06 1/15/2019 UTC: http GET / from 24.63.26.119 (c-24-63-26-119.hsd1.ma.comcast.net) referred by https://www.google.com20:06 1/15/2019 UTC: http GET /style.css from 24.63.26.119 (c-24-63-26-119.hsd1.ma.comcast.net)
Options
Both the the header values and request body are not logged by default, but may be enabled when adding the middleware.
app;
23:15 1/25/2019 UTC: http POST /api/test/?type=sample Headers: { host: "localhost:8080", user-agent: "HTTPie/0.9.9", accept-encoding: "gzip, deflate", accept: "application/json, */*", connection: "keep-alive", content-type: "application/json", content-length: "24" }
Logging the body relies on the body
property of the request to be populated, so make sure to do that before using the logger.
app;app;
23:15 1/25/2019 UTC: http POST /api/test/?type=sample Body: {"VehicleColor":"Blue"}
By default, reverse DNS is used to log the request's host.
app;
5:17 1/8/2019 UTC: https GET /favicon.ico from 66.249.66.152 (crawl-66-249-66-152.googlebot.com)
This can be disabled with the reverseDNS
option.
app;
5:17 1/8/2019 UTC: https GET /favicon.ico from 66.249.66.152
License
MIT © Jesse T Youngblood