node-middleware-log
Ndjson logging middleware.
Installation
$ npm install node-middleware-log
Usage
const logMiddleware = const http = const logOpts = requestBody: true const log = http
express + bole
const logMiddleware = const boleStream = const express = const bole = bole const app = appapp
restify + bunyan
const logMiddleware = const bunyanStream = const restify = const bunyan = const logger = bunyan const server = restifyserver
API
log = logMiddleware(opts, outStream)
Create logging middleware. Options can contain the following values:
- requestBody: log the requests body. Requires
req.body
to exist, which is often patched on by frameworks such asexpress
orrestify
.
log(req, res, cb(err, res))
Log a request and response, calls a callback after it's finished initializing.
Limitations
In order to be compatible with popular frameworks such as express
and
restify
, middleware-log
has had to make tradeoffs. To get properties such
as response size, Node's native properties are being patched on every request.
Also, to log the request size this package also relies on a non-standard
req.body
value to be present. If you'd like to roll your own middleware-log
with different tradeoffs take a look at size-stream
and http-ndjson
.