express-bunyan-logger is an Express middleware that integrates the Bunyan structured logger into web applications. It automatically logs incoming requests and outgoing responses, enriching log entries with detailed metadata such as HTTP method, URL, response status, and response time. It supports flexible configuration for log formats, custom levels based on response status or time, and dynamic inclusion/exclusion of fields. The current stable version is 1.3.3, last published 8 years ago. However, the project's original maintainer has openly stated a lack of time for ongoing maintenance, indicating an effectively abandoned status. While functional, new feature development and proactive security updates are unlikely. Its primary differentiator is deep integration with Bunyan's serialization capabilities, providing rich, machine-readable logs suitable for analysis and integration with log management tools.
npm install express-bunyan-loggerVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates setting up `express-bunyan-logger` for both request and error logging within an Express application. It shows how to pass a custom Bunyan logger instance, configure a custom format string, implement a `levelFn` for dynamic log levels, and utilize the `obfuscate` option for sensitive data. It also highlights how to access the request-specific child logger (`req.log`) within subsequent middleware.
Consider migrating to a more actively maintained logging middleware for Express (e.g., `pino-http`, `morgan` with `winston`/`pino`), or be prepared to fork and maintain the library yourself.
Upgrade to version 1.3.3 or later immediately to address known security vulnerabilities. It's also critical to regularly audit your dependency tree.
Use `require()` syntax for imports. For modern ESM-only projects, consider an alternative logging solution that offers native ESM support.
If you need to obfuscate sensitive data in your logs, upgrade to version 1.3.0 or later and configure the `obfuscate` option in the middleware.
If you rely on `immediate: true` to log at the precise request reception time, ensure you are on version 1.2.0 or higher. For older versions, the log might still be delayed until response is sent, potentially affecting response time calculations.
Install Bunyan: `npm install bunyan` or `npm install express-bunyan-logger bunyan`.
Ensure `app` is correctly initialized as `const app = express();` and that `express` is imported: `const express = require('express');`.Ensure `app.use(require('express-bunyan-logger')());` is placed early in your Express middleware stack, before any routes or other middleware that rely on `req.log`.When initializing `express-bunyan-logger` (or the underlying Bunyan logger), ensure `streams` are configured, e.g., `streams: [{ level: 'info', stream: process.stdout }]`, and that the `level` matches or is lower than the messages you expect to see.