A solid HTTP logger middleware for Express.js applications, also fully compatible with NestJS. This logger provides customizable, detailed logs with fields such as timestamp, HTTP method, URL, status, response time, client IP, user-agent, and more. The lo
npm install tablic-http-loggerA solid HTTP logger middleware for Express.js applications, fully compatible with NestJS. This logger provides customizable, detailed logs with fields such as timestamp, HTTP method, URL, status, response time, client IP, user-agent, and more. The log output is structured in a table-like format, allowing dynamic control over visible fields and timestamp formatting.
ISO or Locale Time).You can install the logger middleware using npm or yarn:
``bash`
npm i tablic-http-logger
You can customize the logger by passing options to the createHttpLogger function. Here's a list of available options and their explanations:
- showTimestamp (boolean, default: true): Display the timestamp in the log.true
- showMethod (boolean, default: ): Display the HTTP method (GET, POST, etc.).true
- showUrl (boolean, default: ): Display the requested URL.true
- showStatus (boolean, default: ): Display the HTTP status code.true
- showResponseTime (boolean, default: ): Display the response time in milliseconds.true
- showClientIP (boolean, default: ): Display the client's IP address.true
- showUserAgent (boolean, default: ): Display the user-agent string.true
- showReferrer (boolean, default: ): Display the referrer (if available).true
- showResponseSize (boolean, default: ): Display the response size.true
- showHttpVersion (boolean, default: ): Display the HTTP version.'iso'
- timeFormat (string, default: ): The format of the timestamp. Can be 'iso' for ISO format or 'short' for a more concise, human-readable local time.
!Screenshot 2025-03-02 at 11 29 00 PM
!Screenshot 2025-03-02 at 11 28 19 PM
`javascript
const express = require('express');
const { createHttpLogger } = require('tablic-http-logger');
const app = express();
// Use the logger middleware
app.use(createHttpLogger({
showTimestamp: true, // Default: true
showMethod: true, // Default: true
showUrl: true, // Default: true
showStatus: true, // Default: true
showResponseTime: true, // Default: true
showClientIP: true, // Default: true
showUserAgent: true, // Default: true
showReferrer: true, // Default: true
showResponseSize: true, // Default: true
showHttpVersion: true, // Default: true
timeFormat: 'iso', // Default: 'iso' (Can be 'iso' or 'short')
}));
// Example route
app.get('/', (req, res) => {
res.send('Hello, world!');
});
app.listen(3000, () => {
console.log('Server is running on port 3000');
});
`
`typescript
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { createHttpLogger } from 'tablic-http-logger';
async function bootstrap() {
const app = await NestFactory.create(AppModule);
app.enableCors();
app.use(createHttpLogger({
// You can customize the logger options here
}));
await app.listen(process.env.PORT ?? 3000);
}
bootstrap();
``
We welcome contributions to improve this project! Here are some ways you can contribute:
- Bug Fixes: If you find a bug, please submit an issue on GitHub and, if possible, provide a fix in a pull request.
- Feature Requests: Have an idea for a new feature? Open an issue with a description of the feature, and we can discuss it.
- Code Improvements: Feel free to suggest or submit code improvements for better performance, cleaner code, etc.
This project is licensed under the MIT License.
If you encounter any issues or have questions, please feel free to open an issue on GitHub. Make sure to include relevant information such as error messages, system environment, and steps to reproduce the issue.