
Security News
ESLint Adds Official Support for Linting HTML
ESLint now supports HTML linting with 48 new rules, expanding its language plugin system to cover more of the modern web development stack.
bunyan-middleware
Advanced tools
Request, response logger middleware using bunyan. Also provides request<>response duration.
Request, response logger middleware for bunyan:
req
res
duration
x-request-id
request header: get it if present, create it otherwise (uuid.v1())req_id
and exposes it as req.reqId
req.log
and res.log
as an id-specialized logger for you to track your request in your entire application, every time you access the request
or response
objectreq
and res
based on bunyan serializers if you do not already have a serializer defined.obscureHeaders
)yarn add bunyan-middleware
or
npm install bunyan-middleware --save
const bunyan = require('bunyan')
const bunyanMiddleware = require('bunyan-middleware')
const express = require('express')
const app = express()
const logger = bunyan.createLogger({ name: 'My App' })
app.use(bunyanMiddleware(
{ headerName: 'X-Request-Id'
, propertyName: 'reqId'
, logName: 'req_id'
, obscureHeaders: []
, logger: logger
, additionalRequestFinishData: function(req, res) {
return { example: true }
}
}
)
app.get('/', function (req, res) {
// now use `req.log` as your request-specialized bunyan logger
req.log.info('YO DAWG!')
res.send('ok')
})
import bunyanMiddleware = require('bunyan-middleware')
X-Request-Id
Will use and forward X-Request-Id
(case insensitive) header when present.
Otherwise it will generate a uuid.v1() and add it to the response headers.
The request id is also available as req.reqId
.
If you are using this with express and mounted app which rewrites req.url
and
you are using bunyan.serializers.req
, then the url in the log output will be
the rewritten url. To fix that bunyan-middleware is using its own request
serializer instead of the default one which is using req.originalUrl
instead.
logger
REQUIRED
headerName
Default: 'X-Request-Id'
propertyName
Default: 'reqId'
additionalRequestFinishData
Default: undefined
req
and res
as arguments returning an object. The elements in the returned object will be added to the fields in the request finish
message.filter
Default: undefined
req
and res
as arguments returning a boolean.
If this functions return value is truthy it will skip all logging for
this request/response.logName
Default: 'req_id'
level
Default: 'info'
request start
and request finish
should be logged.obscureHeaders
Default: null
Set to an array with header names to hide header values from log output.
The output will still show header names, with value set to null
.
Eg: [ 'Authorization' ]
excludeHeaders
Default: null
Set to an array with header names to remove them from log output.
Eg: [ 'Authorization' ]
requestStart
Default: false
verbose
Default: false
req
and res
for request start
and request finish
.MIT. See the LICENCE
file.
bunyan-request - a fork by vvo.
FAQs
Request, response logger middleware using bunyan. Also provides request<>response duration.
The npm package bunyan-middleware receives a total of 7,557 weekly downloads. As such, bunyan-middleware popularity was classified as popular.
We found that bunyan-middleware demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
ESLint now supports HTML linting with 48 new rules, expanding its language plugin system to cover more of the modern web development stack.
Security News
CISA is discontinuing official RSS support for KEV and cybersecurity alerts, shifting updates to email and social media, disrupting automation workflows.
Security News
The MCP community is launching an official registry to standardize AI tool discovery and let agents dynamically find and install MCP servers.