npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

give-logger

v1.1.1

Published

Logger middleware

Downloads

40

Readme

Here is the exact README.md file content that you can copy and paste:

# Winston Logger Middleware for Express

A customizable Winston logger middleware for Express.js applications. It provides easy logging of requests, responses, and errors with customizable log levels and formats.

## Features

- Logs requests and responses in Express.
- Customizable log levels (e.g., `info`, `warn`, `error`).
- Supports both console and file-based logging.
- Supports TypeScript and JavaScript usage.

## Installation

### NPM

You can install this package from npm:

```bash
npm install give-logger

Yarn

If you are using Yarn:

yarn add give-logger

Usage

Basic Setup

In your Express.js app, you can import and use the logger middleware to log incoming requests and responses.

JavaScript

const express = require('express');
const Logger = require('give-logger'); // Import the Logger

const app = express();

// Use the requestLogger middleware to log incoming requests and responses
app.use(Logger.requestLogger());

// Custom routes
app.get('/', (req, res) => {
  
  Logger.info('This is an info log from the root route');
  res.send('Hello, world!');
});

app.get('/error', (req, res) => {
  
  Logger.error('This is an error log');
  res.status(500).send('Something went wrong!');
});

// Start the server
const port = 3000;
app.listen(port, () => {
  console.log(`Server running on http://localhost:${port}`);
});

TypeScript

import express from 'express';
import { Logger } from 'give-logger';

const app = express();

// Use the logger middleware
app.use(Logger.requestLogger());

app.get('/', (req, res) => {
  Logger.info('Handling GET /');
  res.send('Hello, World!');
});

app.get('/error', (req, res) => {
  Logger.error('Handling GET /error');
  res.send('handling GET /error');
});

app.get('/debug', (req, res) => {
  Logger.debug('Handling GET /debug');
  res.send('handling GET /debug');
});

app.get('/warn', (req, res) => {
  Logger.warn('Handling GET /warn');
  res.send('handling GET /warn');
});

const port = 3000;
app.listen(port, () => {
  Logger.info(`Server is running on port ${port}`);
});

Logger Configuration

By default, the logger writes logs to the console and a file (logs/app.log). You can customize the log level and the format.

Available Log Levels

  • info
  • warn
  • error

To change the log level or customize other settings, you can modify the Logger constructor:

const logger = new Logger('warn'); // Sets the default log level to 'warn'

Middleware for Request/Response Logging

To log requests and responses, use the requestLogger middleware. This middleware logs details of incoming HTTP requests and the corresponding responses, including the status code.

app.use(Logger.requestLogger());

The logs will include details such as:

  • HTTP method (e.g., GET, POST)
  • URL
  • Response status code

Development

To contribute to the development of this package:

  1. Clone the repository.

  2. Install dependencies:

    npm install
  3. Build the TypeScript code (if applicable):

    npm run build
  4. Run tests (if applicable):

    npm test
  5. Push your changes and create a pull request.