Security News
pnpm 10.0.0 Blocks Lifecycle Scripts by Default
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
express-bunyan-logger
Advanced tools
A express logger middleware powered by bunyan.
This year as work content change, I have no spare time to maintaining the node modules, if anyone want to take or keep maintaining, just contact me via jky239@gmail.com with Title contains: "Wanted: npm package xxxx". Thx.
npm install express-bunyan-logger
To use the logger:
app.use(require('express-bunyan-logger')());
To use the errorLogger:
app.use(require('express-bunyan-logger').errorLogger());
And you can also pass bunyan logger options to the logger middleware:
app.use(require('express-bunyan-logger')({
name: 'logger',
streams: [{
level: 'info',
stream: process.stdout
}]
}));
Change default format:
app.use(require('express-bunyan-logger')({
format: ":remote-address - :user-agent[major] custom logger"
});
And a child logger will be attached to each request object:
app.use(require('express-bunyan-logger')();
app.use(function(req, res, next) {
req.log.debug('this is debug in middleware');
next();
});
Format string, please go the source code to the metadata. ":name" will print out meta.name; ":name[key]" will print out the property 'key' of meta.name.
Or you can pass a function to options.format. This function accept a object as argument and return string.
Whether to parse user-agent in logger, default is =true=.
Function that translate statusCode into log level. The meta
argument is an object consisting of all the fields gathered by bunyan-express-logger, before exclusions are applied.
function(status, err /* only will work in error logger */, meta) {
// return string of level
if (meta["response-time"] > 30000) {
return "fatal";
} else {
return "info";
}
}
Function that is passed req
and res
, and returns an object whose properties will be added to the meta object passed to bunyan
function(req, res) {
if (req.user) {
return {
_id: req.user._id,
name: req.user.name
}
}
}
Array of string, Those fields will be excluded from meta object which passed to bunyan
An object of bunyan serializers. They are passed on to bunyan. The default serializers are defined as follows:
{
req: bunyan.stdSerializers.req,
res: bunyan.stdSerializers.res,
err: bunyan.stdSerializers.err
}
Write log line on request instead of response (for response times)
By default, express-bunyan-logger
will generate an unique id for each request, and a field 'req_id' will be added to child logger in request
object.
If you have already use other middleware/framework to generate request id, you can pass a function to retrieve it:
// suppose connect-requestid middleware is already added.
app.use(require('express-bunyan-logger')({
genReqId: function(req) {
return req.id;
}
});
(The BSD License)
Copyright (c) 2013, Villa.Gao <jky239@gmail.com>;
FAQs
a bunyan logger middleware for express
The npm package express-bunyan-logger receives a total of 7,255 weekly downloads. As such, express-bunyan-logger popularity was classified as popular.
We found that express-bunyan-logger demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 6 open source maintainers 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
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
Research
Security News
Socket researchers have discovered multiple malicious npm packages targeting Solana private keys, abusing Gmail to exfiltrate the data and drain Solana wallets.