🚨 Shai-Hulud Strikes Again:834 Packages Compromised.Technical Analysis →
Socket
Book a DemoInstallSign in
Socket

debug-instanced

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

debug-instanced

Like the 'debug' module, but automatically labels output with an instance ID. Useful when dealing with many different objects.

latest
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

debug-instanced

Like the debug module, but automatically labels output with an instance ID. Useful when dealing with many different objects.

Usage

See also example.js in the package.

"use strict";

const debugInstanced = require("debug-instanced")("example");

function doThing() {
	let debug = debugInstanced("foo");
	debug("line one");
	2 + 2;
	debug("line two");
}

doThing();
doThing();

This would output the following:

~/projects/debug-instanced> DEBUG=* node example.js
  example [e04ab8] created instance (type: foo) +0ms
  example [e04ab8] line one +1ms
  example [e04ab8] line two +0ms
  example [931af6] created instance (type: foo) +0ms
  example [931af6] line one +1ms
  example [931af6] line two +1ms

As you can see, the output from each 'instance' of the call to doThing is labelled with its own unique ID, that is generated when debugInstanced is called.

The API is basically the same as that of debug, except there's an extra level of function invocation. Normally when you call the function exported by debug you immediately get a function that lets you log things; but in debug-instanced, that gets you an instance creation function instead. That instance creation function, when called, returns the logging function you need - and it's called the same way as the logging function in debug.

The enabled property is available on the instance creation function, instead of on the logging function where it would be in debug.

FAQs

Package last updated on 22 Jun 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts