Custom HTTP logger middleware
npm install mb64-logs About the mb64-logs package:
``markdown
mb64-logsmb64-logs
is an npm package that provides middleware for logging detailed request and response information in your Express.js applications. It helps developers gain insights into the API requests and responses by logging comprehensive details about each transaction, making it easier to debug and monitor their applications.
mb64-logs
Installation
You can install using npm:
`
sh
`
npm install mb64-logs
mb64-logs
Usage
Here's an example of how to use in an Express.js application:
`
javascript
Server is running on http://localhost:${port}
const express = require("express");
const cors = require("cors");
const mblogs = require("mb64-logs");
const app = express();
const port = 3000;
app.use(cors());
mblogs(app);
app.post("/", (req, res) => {
res.send("mblogs");
});
app.listen(port, () => {
console.log();
`
});
mb64-logs
$3
Here's an example of the detailed request log that will produce:
`
`
--- Detailed Request Log ---
Method: POST
URL: /?api=asdosd
Status Code: 200
Status Description: OK
IP Address: ::1
HTTP Version: HTTP/1.1
Content Length: 6
User-Agent: PostmanRuntime/7.40.0
Response Time: undefined ms
Request Headers: {
"content-type": "application/json",
"user-agent": "PostmanRuntime/7.40.0",
"accept": "/",
"postman-token": "99ed9ddd-4a4c-4811-a377-b4a26e756df3",
"host": "localhost:3000",
"accept-encoding": "gzip, deflate, br",
"connection": "keep-alive",
"content-length": "26"
}
Request Params: {}
Request Query: {
"api": "asdosd"
}
Request Body: {
"type": "mblogs"
}
Response Body: mblogs
----------------------------------
POST /?api=asdosd 200 OK ::1 HTTP/1.1 6 "PostmanRuntime/7.40.0" - 0.790 ms
``
Features
- Logs detailed information about each request and response, including headers, parameters, query strings, and body.
- Easy to integrate with Express.js applications.
- Helps with debugging and monitoring of API requests by providing comprehensive logs that detail each aspect of the transaction.
Contributing
Contributions are welcome! Please open an issue or submit a pull request on GitHub.
License
This project is licensed under the MIT License.
Author
Manoj Gowda B R
Contact
- Email: manojgowda8951@gmail.com
- LinkedIn: Manoj Gowda B R
---