npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

express-dynamic-logger

v1.1.3

Published

Express middleware for dynamic, configurable logging of incoming requests, outgoing responses, missing routes and manual developer logs with custom prefixes, header redaction and flexible options.

Downloads

31

Readme

express-dynamic-logger

Minimal middleware for Node.js/Express to provide dynamic, configurable logging with both automatic request/response logs and manual developer logs.


📦 Installation

npm install express-dynamic-logger

Or with Yarn:

yarn add express-dynamic-logger

🚀 Usage

Ensure you register body-parsing middleware before mounting the logger so that req.body is populated correctly:

const express = require('express');
const app = express();

// 1. Register body parsers
app.use(express.json());       // for JSON bodies
app.use(express.urlencoded({ extended: true })); // for URL-encoded bodies

// 2. Mount the dynamic logger

const logger = require('express-dynamic-logger');
app.use(logger()); // default options

To customize the logger, pass options into the factory:

app.use(logger({
  logPrefix: '[APP]',
  printAutoLogs: true,
  printManualLogs: true,
  // ...other options...
}));

Manual Logging

Use req.log in your route handlers to emit custom messages at any level:

app.get('/items', (req, res) => {
  req.log.debug('Fetching items', { filter: req.query });
  req.log.info('Items fetched successfully');
  req.log.warn('Response size is large');
  req.log.error('Failed to process item', { id: 123 });
  req.log.fatal('Critical failure!');
  res.send(items);
});

This demonstrates how to call req.log.debug/info/warn/error/fatal for manual logs.


⚙️ Configuration Options

| Option | Type | Default | Description | |---------------------------|------------|-------------------------------|--------------------------------------------------------------------------------------------------| | level | string | 'info' | Log level for automatic logs ([INI], [END]). | | printAutoLogs | boolean | true | Whether to print automatic logs. | | printManualLogs | boolean | true | Whether to print developer-invoked logs (req.log.*).
| skipPreflight | boolean | false | Whether to skip logging CORS preflight (OPTIONS) requests | | | requestIdHeader | string | 'x-request-id' | Header name used to propagate or generate a request ID. | | autoGenerateRequestId | boolean | true | Generate a UUID request ID if the header is missing. | | skipPaths | string[] | ['/health','/favicon.ico'] | Array of routes to ignore (no logging). | | deepHeaders | boolean | true | Include all headers; if false, filter out common browser headers. | | redact | string[] | ['authorization'] | List of header names to mask with ****. | | logPrefix | string | '' | Global prefix prepended to every log entry. | | statusPrefix100 | string | '' | Prefix for 1xx HTTP status logs. | | statusPrefix200 | string | '' | Prefix for 2xx HTTP status logs. | | statusPrefix300 | string | '' | Prefix for 3xx HTTP status logs. | | statusPrefix400 | string | '' | Prefix for 4xx HTTP status logs. | | statusPrefix500 | string | '' | Prefix for 5xx HTTP status logs. | | levelPrefixDebug | string | '' | Prefix for req.log.debug messages. | | levelPrefixInfo | string | '' | Prefix for req.log.info messages. | | levelPrefixWarn | string | '' | Prefix for req.log.warn messages. | | levelPrefixError | string | '' | Prefix for req.log.error messages. | | levelPrefixFatal | string | '' | Prefix for req.log.fatal messages. |


✨ Examples

Default Behavior

app.use(logger());
app.get('/ping', (req, res) => {
  req.log.info('Ping handler');
  res.send('pong');
});

Disable Auto-Logs

app.use(logger({ printAutoLogs: false }));

Disable Manual Logs

app.use(logger({ printManualLogs: false }));

Skip Paths and Custom Request ID

app.use(logger({
  skipPaths: ['/health'],
  requestIdHeader: 'x-custom-id',
  autoGenerateRequestId: false
}));

Filter and Redact Headers

app.use(logger({
  deepHeaders: false,
  redact: ['authorization', 'cookie']
}));

Custom HTTP Status Prefixes

app.use(logger({
  statusPrefix200: '[OK]',
  statusPrefix400: '[BAD_REQ]',
  statusPrefix500: '[ERR]'
}));

Prefix Configuration Only

app.use(logger({
  logPrefix: '[APP]',
  statusPrefix200: '[SUCCESS]',
  statusPrefix400: '[CLIENT_ERR]',
  statusPrefix500: '[SERVER_ERR]',
  levelPrefixDebug: '🐛',
  levelPrefixInfo: 'ℹ️',
  levelPrefixWarn: '⚠️',
  levelPrefixError: '❌',
  levelPrefixFatal: '💀'
}));

Ignore preflight CORS

app.use(logger({
  skipPreflight: true
}));

🚧 Error Resilience

All logging logic runs inside a single try/catch, so internal errors will be printed via console.error without interrupting the server.


📄 License

This project is open source under the MIT License.