HTTP Request Logger Middleware
raw JSON →logger-request is an HTTP request logging middleware for Node.js, primarily designed for Express applications. It leverages the Winston logging library (specifically Winston v2.3.1 as of its last release, 3.8.0) to provide flexible output options including file logging, console output, and integration with other Winston transports like MongoDB. Key features include daily log rotation, customizable log fields such as process ID, referrer, authentication status, transfer rates, and user agent. The package reached its latest version, 3.8.0, in 2017, and has not received updates since, making it incompatible with modern Node.js versions and the significantly evolved Winston v3+ ecosystem. Its release cadence was active in the mid-2010s but has ceased, rendering it effectively unmaintained.
Common errors
error TypeError: logger.transports.Console is not a constructor ↓
node_modules only contains winston@2.x if you intend to use logger-request. If your project requires Winston v3+, you must migrate away from logger-request. error Error: Cannot find module 'winston' ↓
npm install winston@2 (to match the version logger-request expects) or npm install winston if you are using an older npm that resolves peer dependencies automatically. error TypeError: app.use requires middleware functions but got a [object Undefined] ↓
logger-request is correctly installed via npm install logger-request. Check for any installation errors or conflicts in your node_modules directory. Warnings
breaking The package is hardcoded to use Winston v2.3.1. It is not compatible with Winston v3.x or later due to significant API changes in Winston's major versions. Attempting to use a newer Winston version will result in errors. ↓
breaking The package has not been updated since 2017 and has a Node.js engine requirement of `>=4`. It is not officially tested or supported on modern Node.js versions and may encounter runtime issues or security vulnerabilities. ↓
gotcha The `deprecated` option within the `logger(options)` object does not indicate a deprecation of the package itself or a feature. Instead, it's a flag (default `false`) that alters the timing of log writing from the default `listener` to after `res.end()` (if `true`). This naming can be confusing. ↓
Install
npm install logger-request yarn add logger-request pnpm add logger-request Imports
- logger wrong
const { logger } = require('logger-request')correctimport logger from 'logger-request' - LoggerMiddleware wrong
import { LoggerMiddleware } from 'logger-request'correctconst logger = require('logger-request'); app.use(logger(options));
Quickstart
const express = require('express');
const logger = require('logger-request');
const app = express();
// Configure the logger to write to 'app.log' and also display to console
app.use(logger({
filename: 'app.log',
console: true,
daily: true, // Rotate log file daily
winston: {
level: 'info',
json: true,
timestamp: true
},
custom: {
pid: true, // Log process ID
referer: true, // Log HTTP referer header
agent: true // Log user-agent header
}
}));
app.get('/', (req, res) => {
res.send('Hello World!');
});
app.listen(3000, () => {
console.log('Server running on port 3000');
});