log-express
v1.0.2
Published
log-express is a lightweight and customizable middleware for Express.js that provides comprehensive logging of all incoming user requests. Designed to be easy to integrate and configure, this package helps you keep track of request details, which can be i
Downloads
4
Maintainers
Readme
log-express
log-express is a lightweight and customizable middleware for Express.js that provides comprehensive logging of all incoming user requests. Designed to be easy to integrate and configure, this package helps you keep track of request details, which can be invaluable for debugging, monitoring, and analyzing traffic patterns.
Features
- Customizable Logging: Choose log levels, enable file logging, and more.
- Console and File Logging: Logs can be sent to the console and/or saved to files.
- Daily Log Rotation: Optional daily log file creation.
- Detailed Request Information: Logs request method, URL, status code, response time, and client IP.
Installation
To install log-express
, use npm:
npm install log-express
Usage
Basic Setup
To use log-express
in your Express application, follow these steps:
- Create a new Express application or open an existing one.
- Install the
log-express
package. - Configure and use the middleware in your application.
const express = require("express");
const log-express = require("log-express"); // Adjust this if the package name is different
const app = express();
// Configure the middleware
const loggerOptions = {
logLevel: "debug", // Adjust log level: trace, debug, info, warn, error, fatal
consoleLog: true, // Set to false to disable console logging
saveLogs: true, // Set to true to enable file logging
logPerDay: true, // Set to true to enable logging per day (e.g., logs/system-2024-09-05.logs)
};
// Use the middleware
app.use(log-express(loggerOptions));
// Define routes
app.get("/", (req, res) => {
res.send("Welcome to the home page!");
});
app.get("/about", (req, res) => {
res.send("About us page");
});
// Start the server
app.listen(3000, () => {
console.log("Server started at http://localhost:3000");
});
Middleware Options
logLevel
: Set the logging level. Options:trace
,debug
,info
,warn
,error
,fatal
.consoleLog
:true
to log to the console,false
to disable console logging.saveLogs
:true
to save logs to a file,false
otherwise.logPerDay
:true
to create a new log file each day,false
to use a single file.
Contributing
We welcome contributions to log-express
. If you'd like to contribute, please follow these steps:
Fork the repository: Click on the "Fork" button at the top right of this page.
Clone your fork:
git clone https://github.com/piyushPb/log-express.git
Create a new branch:
git checkout -b feature-branch
Make your changes and commit them:
git add . git commit -m "Add new feature"
Push to your fork:
git push origin feature-branch
Create a pull request: Go to the original repository and create a pull request from your fork's branch.
For detailed guidelines, please refer to our CONTRIBUTING.md file.
License
log-express
is licensed under the MIT License. See the LICENSE file for more information.
Acknowledgements
- Express.js: The framework that
log-express
extends. - Contributors: Thanks to all contributors who have helped improve the project.
Contact
For questions or support, please open an issue on GitHub.