1.1.2 • Published 6 months ago
ashish_logger-middleware v1.1.2
ashish_logger-middleware
A Winston-based logger middleware for Node.js applications with console-only logging support.
Features
- Console-only logging (no file storage)
- Colorized output for better readability
- Request logging middleware for Express
- Warning logger for deprecation notices and resource limits
- Error logging middleware
- Timestamp-based logging
- JSON metadata support
Installation
npm install ashish_logger-middleware
Usage
const express = require('express');
const { requestLogger, errorLogger, warningLogger, logger } = require('ashish_logger-middleware');
const app = express();
// Use request logger middleware
app.use(requestLogger);
// Your routes here
app.get('/', (req, res) => {
logger.info('Home route accessed');
res.send('Hello World');
});
// Example of using warning logger
warningLogger({
message: "API version 1 is deprecated",
code: "DEPRECATED_API",
details: {
version: "1.0",
newVersion: "2.0"
}
});
// Use error logger middleware (should be last)
app.use(errorLogger);
app.listen(3000, () => {
logger.info('Server started on port 3000');
});
Warning Logger
The warning logger is designed for logging warnings such as:
- Deprecated API versions
- Resource usage limits
- Performance warnings
- Configuration issues
warningLogger({
message: "Your warning message", // Required: Warning message
code: "WARNING_CODE", // Optional: Warning code identifier
details: { // Optional: Additional warning details
// Any relevant warning details
}
});
Log Format
Logs will be displayed in the console with the following format:
[timestamp] level: message {additional metadata}
License
ISC