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

cls-debug-logger

v0.1.2

Published

A logger that makes use of continuation-local-storage (cls) to record logs with the same sessionId throughout the function call chain including callbacks and event emitter handlers.

Readme

cls-debug-logger

Uses the cls-hooked fork of continuation-local-storage to maintain a session id with all logs.

All async calls, callbacks and event emitters will maintain references to the session ids.

See

Example Usage

const logger: ILogger = createLogger('my_namespace');

// Session
await logger.session(async () => {
  logger.log('%d: %s', 4, 'a log message');

  // Sub session
  await logger.session(async () => {
    logger.log('%d: %s', 10, 'a sub log message');
  }, 'my sub-session id');
}, 'my session id');

Output:

my_namespace {"message":"4: a log message","session":"my session id"} +2ms
my_namespace {"message":"10: a sub log message","session":"my session id","subSessions":["my sub-session id"]} +1ms

Log Output: Logger type

By default this logger uses the Debug logger. Any logging engine can be used with this logger by Implementing the ILogProvider class.

API

createLogger(namespace: string, logProvider: ILogProvider): ILogger

  • return: ILogger
  • params:
    • namespace: Has two uses:
      • With Debug to enable and disable the logger via the DEBUG env variable.
      • With cls, this is the cls namespace id where the session ids will be stored. Any logger created with this namespace will have access to the active sessions within it. Every log will gain the id of the active session
    • logProvider: By default this will use the Debug logger, a custom log engine (e.g. winston) can be used instead by passing the implementation here.

Create a logger instance.

ILogger

log(message: any, ...args: any[]): void

  • return: ILogger
  • params:
    • message: The string message or object to be logged. The can be a format template whose elements can be populated by the supplied args. @see util.format and @see util.formatWithOptions
    • args: Any arguments to fill the format string

Log a message the current log provider

session<T>(session: () => Promise<T>, sessionId?: string): Promise<T>

  • return: The result of the session callback
  • params:
    • session The callback to execute in the session context
    • sessionId The id of the session context, this will be outputted with each log. Optional: a Uuid will be created

Create a logging session. All logs made in the executing session with be labelled with a session id.

Parent session and sub-session. The first session created is considered a parent or outer session. Any session created within that session context (essentially by calling this function again from the callback 'session') is called a sub-session. A list of subsession ids will also be outputted to the logs. Subsessions are really useful to label smaller code paths within a session, especially when tracking each item in a promise.all call where each execution can have its own subsession.

bind<T>(func: () => T): () => T

  • return: the result of the callback func
  • params:
    • func The fucntion to bind to the active session. The function will now log with the session ids of active session.

Bind a function call back to the currently executing session

bindEmitter(emitter: EventEmitter): void

  • return: void
  • params:
    • emitter The emitter to bind to the active session. All the listeners of the event emitter will not log will the active session ids

Bind an EventEmitter to the currently executing session

ILogProvider

`log(logMessage: ILogMessage): void``

  • return: void
  • param:
    • logMessage The message to log

Log the provided object logMessage

ILogMessage

  message: any;
  session?: string;
  subSessions?: string[];