explaingit

debug-js/debug

11,440JavaScriptAudience · developerComplexity · 2/5Setup · easy

TLDR

A tiny JavaScript utility that lets you add labeled diagnostic log messages to your code and turn specific groups on or off with an environment variable, replacing scattered console.log calls.

Mindmap

mindmap
  root((debug))
    What it does
      Labeled log messages
      Toggle by namespace
    Features
      Color per namespace
      Timing between calls
      Printf formatting
    Environments
      Node.js
      Browser devtools
    Config
      DEBUG env var
      Wildcard matching
      Exclude with minus sign
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Replace scattered console.log calls in a Node.js app with labeled debug messages that can be toggled on or off without code changes.

USE CASE 2

Filter log output during development by namespace so only the module you are debugging produces messages.

USE CASE 3

Add timing information to logs to spot where your application is slow between consecutive operations.

Tech stack

JavaScriptNode.js

Getting it running

Difficulty · easy Time to first run · 5min
No license information was mentioned in the explanation.

In plain English

The debug package is a small JavaScript utility for printing diagnostic messages during development. Instead of scattering regular console.log calls throughout your code that you then have to remove before shipping, you label each message with a namespace and turn entire groups of messages on or off with an environment variable. Only the messages you care about right now show up, everything else stays silent. You install it like any other JavaScript package and use it by creating a named logger for each part of your code. For example, a module called "worker" might have two loggers, "worker:a" and "worker:b". Setting the DEBUG environment variable to "worker:" turns both on at once. You can also exclude specific namespaces by prefixing them with a minus sign, so "DEBUG=,-worker:a" would show everything except that one. Each namespace gets its own color in the terminal output, which helps when multiple parts of an application are logging at the same time. Debug also shows how much time passed between consecutive calls to the same logger, which can help spot where an application is slow. When output is not going to a terminal, timestamps switch to a standard date format more suited to log files. The library works both in Node.js (server-side JavaScript) and in web browsers, where the browser's developer tools console displays the colored output. In the browser, the list of enabled namespaces is saved in localStorage so your debug settings persist across page reloads. Formatting follows the printf style familiar from C and other languages, with built-in support for strings, numbers, JSON, and object pretty-printing, plus the ability to register custom formatters.

Copy-paste prompts

Prompt 1
My Node.js app has debug logs scattered everywhere. Show me how to use the debug package to namespace my logs such as 'app:db' and 'app:auth' and toggle them with the DEBUG environment variable.
Prompt 2
I want to enable all debug logs in my app except one noisy module. Show me the DEBUG env var syntax to include everything but exclude a specific namespace.
Prompt 3
How do I add a custom formatter to the debug package so it prints objects in a special way, like formatting a Buffer as hex?
Prompt 4
Show me how to use the debug package in a browser, including how it saves enabled namespaces in localStorage across page reloads.
Open on GitHub → Explain another repo

← debug-js on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.