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 🙏

© 2025 – Pkg Stats / Ryan Hefner

winston-express-request-logger

v1.0.3

Published

Winston based express logger that includes request, process, unique id and user information

Readme

Winston express request loggger

Winston express request logger is a library that extends winston to print out request, process, error and user information. It also prints out a unique identifier per request to be able to track which request a log line belongs to.

List of elements added to the log as a prefix

  • Process id e.g pId: 9472
  • Unique request identifier e.g uId: cidstmimz000ob43upnw7xp2b
  • User identifier e.g cId: 123
  • User ip address e.g cIP: 127.0.0.1
  • User action e.g cAction: GET /api/user/55dc48232a8708a3078e995a

Additionally if there is an err object as part of the log arguments the error stack trace will be printed in the logs.

install

npm install winston-express-request-logger

initialisation

There are two steps to initialise the module. The first is to initialise your logger which takes the same arguments as a winston logger. This needs winston as a prerequisite to be able to create the transports. This step needs to be done before the logger is used.

// Initialise logger
var winston = require('winston');
var winstonExRegLogger = require("winston-express-request-logger");
winstonExRegLogger.createLogger({
    transports: [
        new (winston.transports.File)({
            filename: 'knugget-service.log',
            handleExceptions: true,
            timestamp:true,
            level:"info"
        }),
        new (winston.transports.Console)({
            handleExceptions: true,
            timestamp: true,
            level:"info"
        })
    ],
    exitOnError: false
});

The second step is to add the request interceptor to express in order to get the necessary information from the express request object. The user id in this case is retrieved by getting the cookie named id from express (req.cookies['id']).

// Request Interceptor setup
var winstonExRegLogger = require("winston-express-request-logger");
function configureApp(app, env) {
	.....
	.....
	app.use(winstonExRegLogger.requestDetails);
	.....
	.....
}

An optional step if you would like to override the user id printed by the module, is to add your own interceptor that initialises the req.loggerUserId variable. This needs to go before the requestDetails one.

// Custom Request Interceptor setup
var winstonExRegLogger = require("winston-express-request-logger");
function configureApp(app, env) {
	.....
	.....
	var customUserID = function customUserID(req, res, next) {
        req.loggerUserId = 123;
        next();
    };
    app.use(customUserID);

	app.use(winstonExRegLogger.requestDetails);
	.....
	.....
}

logging

After the initialisation you can use the logger exactly as winston logger (log level, dynamic number of arguments). The only difference is that if you would like the request information to be printed the first argument of your logger needs to be the req object. Additionally, any Error object would be printed based on its stack trace.

// Logging
var logger = require("winston-express-request-logger").getLogger();

logger.info(req,"Get the user's details"); 
// prints 2015-08-26T13:59:16.659Z - info: pId:9677 - uId:cidsul8ry000pgt3ugwebvei5 - cId:55dc48232a8708a3078e995a - cIP: 127.0.0.1 - cAction: GET /api/user/55dc48232a8708a3078e995a Get user details

logger.info("Get the user's details");
// prints 2015-08-26T13:59:16.659Z - info: Get the user's details