Skip to content

winnerezy/logwin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

logwin

logwin is a lightweight Express.js middleware for logging HTTP request and response details. It captures critical information such as route, method, status code, response time, IP address, and user-agent, and highlights server-side errors for easier debugging.

Installation

Install logwin via npm:

npm install logwin

Usage

Importing the Middleware

Import logwin in your Express.js application:

import express from "express";
import logwin from "logwin";

const app = express();

// Apply the middleware
app.use(logwin);

// Define routes
app.get("/", (req, res) => {
  res.send("Hello, World!");
});

app.listen(3000, () => {
  console.log("Server running on http://localhost:3000");
});

Features

  • Logs the following details for every request:
    • HTTP method
    • Route
    • Response status code
    • Processing time in milliseconds
    • Client IP address
    • User-Agent string
    • Error details for server-side errors
  • Highlights errors with status codes between 500 and 511.

Output Example

Below is an example log generated by logwin:

{
  "route": "/example-route",
  "method": "GET",
  "statusCode": 200,
  "time": "50ms",
  "duration": "2025-01-03T10:00:00.000Z",
  "ip": "127.0.0.1",
  "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36",
  "error": null
}

Log Fields

Field Description
route The URL path of the incoming request.
method The HTTP method (e.g., GET, POST, etc.).
statusCode The HTTP status code of the response.
time The time taken to process the request, in ms.
duration Timestamp when the request was processed.
ip The IP address of the client making the request.
user-agent The User-Agent string from the request header.
error Error message if status code is 500-511, or null.

Contribution

Contributions are welcome! Feel free to open issues or submit pull requests on the GitHub repository.

License

This package is licensed under the MIT License. See the LICENSE file for more details.

Support

If you encounter any issues, please open an issue on the GitHub repository.

About

A simple and efficient logger for node

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published