### Install debug.js using npm Source: https://github.com/debug-js/debug/blob/master/README.md Install the debug package using npm. This is the first step to using the library in your project. ```bash npm install debug ``` -------------------------------- ### Debug.js Worker Example Source: https://github.com/debug-js/debug/blob/master/README.md This example shows how to use debug with multiple namespaces ('worker:a', 'worker:b') to differentiate debug output from different parts of a worker module. ```javascript var a = require('debug')('worker:a') , b = require('debug')('worker:b'); function work() { a('doing lots of uninteresting work'); setTimeout(work, Math.random() * 1000); } work(); function workb() { b('doing some work'); setTimeout(workb, Math.random() * 2000); } workb(); ``` -------------------------------- ### Basic debug.js Usage in Node.js Source: https://github.com/debug-js/debug/blob/master/README.md Initialize debug with a namespace and use the returned function for debug statements. This example demonstrates basic HTTP server debugging. ```javascript var debug = require('debug')('http') , http = require('http') , name = 'My App'; // fake app debug('booting %o', name); http.createServer(function(req, res){ debug(req.method + ' ' + req.url); res.end('hello\n'); }).listen(3000, function(){ debug('listening'); }); // fake worker of some kind require('./worker'); ``` -------------------------------- ### Enable debug output on Windows CMD Source: https://github.com/debug-js/debug/blob/master/README.md Set the DEBUG environment variable using the 'set' command in Windows Command Prompt. This example enables all debug output except 'not_this'. ```cmd set DEBUG=*,-not_this ``` -------------------------------- ### Enable debug output on Windows PowerShell Source: https://github.com/debug-js/debug/blob/master/README.md Set the DEBUG environment variable using the $env:DEBUG syntax in PowerShell. This example enables all debug output except 'not_this'. ```powershell $env:DEBUG = "*,-not_this" ``` -------------------------------- ### Add Custom Formatter in Debug.js Source: https://github.com/debug-js/debug/blob/master/README.md Extend the debug.formatters object to add custom formatters. This example adds a hex formatter for Buffers. ```javascript const createDebug = require('debug') createDebug.formatters.h = (v) => { return v.toString('hex') } // …elsewhere const debug = createDebug('foo') debug('this is hex: %h', new Buffer('hello world')) // foo this is hex: 68656c6c6f20776f726c6421 +0ms ``` -------------------------------- ### Enable Debug with Namespaces Source: https://github.com/debug-js/debug/blob/master/README.md Demonstrates enabling specific debug namespaces using a string that can include wildcards and exclusions. This is executed via a Node.js script. ```bash $ DEBUG=foo node -e 'var dbg = require("debug"); dbg.enable("bar"); console.log(dbg.enabled("foo"))' => false ``` -------------------------------- ### Initialize and Use Debuggers in Browser Source: https://github.com/debug-js/debug/blob/master/README.md Initialize separate debug instances for different namespaces ('worker:a', 'worker:b') and log messages at intervals. ```javascript a = debug('worker:a'); b = debug('worker:b'); setInterval(function(){ a('doing some work'); }, 1000); setInterval(function(){ b('doing some work'); }, 1200); ``` -------------------------------- ### Dynamic Debug Enabling and Disabling Source: https://github.com/debug-js/debug/blob/master/README.md Demonstrates how to enable and disable debug namespaces dynamically using the `enable()` and `disable()` methods. It also shows how to check the enabled status of a specific namespace. ```APIDOC ## enable(namespaces) ### Description Enables debug logging for the specified namespaces. This completely overrides any previously set DEBUG environment variable or enable calls. ### Parameters #### Path Parameters - **namespaces** (string) - Required - A string of namespaces to enable, separated by colons. Wildcards are supported. ### Method `debug.enable(namespaces)` ## disable() ### Description Disables all currently enabled debug namespaces. It returns the previously enabled namespaces, which can be used to temporarily disable debugging. ### Method `debug.disable()` ### Returns - **string** - The string of namespaces that were previously enabled. ``` -------------------------------- ### Run Node.js app with debug enabled on Windows CMD Source: https://github.com/debug-js/debug/blob/master/README.md Combine setting the DEBUG environment variable with running your Node.js application in a single command. ```cmd set DEBUG=* & node app.js ``` -------------------------------- ### debug.enable(namespaces) — Enable namespaces at runtime Source: https://context7.com/debug-js/debug/llms.txt Activates one or more debug namespaces programmatically. Accepts a comma- or space-delimited string of namespace patterns, including wildcards (`*`) and exclusions (prefix with `-`). Calling `enable()` completely overrides any previously active set. ```APIDOC ## debug.enable(namespaces) ### Description Enables one or more debug namespaces programmatically, overriding any previous settings. Supports wildcards and exclusions. ### Parameters #### namespaces - **namespaces** (string) - Required - A comma- or space-delimited string of namespace patterns (e.g., `'app:*, -app:verbose'`). ### Usage ```javascript const debug = require('debug'); const log = debug('worker:task'); // Initially disabled console.log(log.enabled); // false // Enable just this namespace debug.enable('worker:task'); console.log(log.enabled); // true // Enable all except verbose tracing debug.enable('*,-worker:verbose'); ``` ### Overriding Previous Settings Calling `debug.enable()` replaces the current set of enabled namespaces entirely. ``` -------------------------------- ### Create and Use Namespaced Debug Loggers Source: https://context7.com/debug-js/debug/llms.txt Create loggers for different application parts using namespaces. Enable specific namespaces programmatically or via the DEBUG environment variable. Output includes namespace, time diff, and formatted messages. ```javascript const debug = require('debug'); // Create loggers for different parts of an application const httpLog = debug('app:http'); const dbLog = debug('app:db'); const cacheLog = debug('app:cache'); // Enable specific namespaces before using them (or use the DEBUG env var) debug.enable('app:http,app:db'); httpLog('GET %s %d', '/users', 200); // => app:http GET /users 200 +0ms dbLog('query took %d ms: %o', 42, { table: 'users', rows: 5 }); // => app:db query took 42 ms: { table: 'users', rows: 5 } +1ms cacheLog('this will NOT appear — namespace not enabled'); // Run from the command line: // DEBUG=app:* node app.js — enable all app namespaces // DEBUG=app:http node app.js — only http // DEBUG=app:*,-app:cache node app.js — all except cache ``` -------------------------------- ### Enable Debug Namespaces Programmatically Source: https://context7.com/debug-js/debug/llms.txt Activates one or more debug namespaces programmatically. Accepts a comma- or space-delimited string of namespace patterns, including wildcards and exclusions. Calling enable() completely overrides any previously active set. ```javascript const debug = require('debug'); const log = debug('worker:task'); // Disabled initially console.log(log.enabled); // false // Enable just this namespace debug.enable('worker:task'); console.log(log.enabled); // true // Enable everything except verbose tracing debug.enable('*,-worker:verbose'); // Re-enable from a previously saved string (see disable()) const saved = debug.disable(); // ... later ... debug.enable(saved); ``` -------------------------------- ### debugInstance.extend(namespace[, delimiter]) Source: https://context7.com/debug-js/debug/llms.txt Creates a child debug namespace that inherits the parent's custom log function. The new namespace is formed by joining the parent namespace with the provided namespace, using an optional delimiter. ```APIDOC ## `debugInstance.extend(namespace[, delimiter])` — Create a child namespace Creates a new debug instance whose namespace is the parent namespace joined to `namespace` with `delimiter` (default `:`). The child inherits the parent's custom `log` function. ```js const debug = require('debug'); const authLog = debug('auth'); authLog.log = console.log.bind(console); // redirect to stdout const signLog = authLog.extend('sign'); // namespace: 'auth:sign' const loginLog = authLog.extend('login'); // namespace: 'auth:login' const rawLog = authLog.extend('raw', ''); // namespace: 'authraw' (empty delimiter) debug.enable('auth:*'); authLog('initialized'); // auth initialized +0ms signLog('token issued'); // auth:sign token issued +0ms loginLog('user logged in'); // auth:login user logged in +1ms // Custom delimiter example const httpLog = debug('http'); const getLog = httpLog.extend('GET', ' '); // namespace: 'http GET' debug.enable('http GET'); getLog('/api/users'); ``` ``` -------------------------------- ### Enable Debugging in Browser with localStorage Source: https://github.com/debug-js/debug/blob/master/README.md Persist debug enable state in the browser using localStorage. Set `localStorage.debug` to a pattern like 'worker:*' and refresh the page. ```javascript localStorage.debug = 'worker:*' ``` -------------------------------- ### Run Node.js app with debug enabled on Windows PowerShell Source: https://github.com/debug-js/debug/blob/master/README.md Combine setting the DEBUG environment variable with running your Node.js application in a single command. ```powershell $env:DEBUG='app';node app.js ``` -------------------------------- ### Dynamically Enable Debug Logs Source: https://github.com/debug-js/debug/blob/master/README.md Use `debug.enable()` to dynamically enable debug namespaces. Calling `enable()` overrides any previously set DEBUG environment variable. ```javascript let debug = require('debug'); console.log(1, debug.enabled('test')); debug.enable('test'); console.log(2, debug.enabled('test')); debug.disable(); console.log(3, debug.enabled('test')); ``` -------------------------------- ### Initialize and Use Debug Namespaces in Application Code Source: https://context7.com/debug-js/debug/llms.txt Initialize debug instances with specific namespaces in your application code. Use these instances like console.log for conditional logging. Note that in Chromium-based browsers, debug messages only appear when the DevTools 'Verbose' log level is enabled. ```javascript const debug = require('debug'); const workerA = debug('worker:a'); const workerB = debug('worker:b'); setInterval(() => workerA('heartbeat ping'), 1000); setInterval(() => workerB('processing queue'), 1200); ``` -------------------------------- ### Configure Debug via Environment Variables (Node.js) Source: https://context7.com/debug-js/debug/llms.txt Control debug behavior without code changes using environment variables. This includes enabling specific namespaces, suppressing timestamps or colors, and setting the inspection depth. ```bash # Enable namespaces DEBUG=app:* node server.js DEBUG=app:http,app:db node server.js DEBUG=*,-connect:* node server.js # all except connect:* # Windows CMD set DEBUG=app:* & node server.js # Windows PowerShell $env:DEBUG='app:*'; node server.js # Tune output detail DEBUG=* DEBUG_HIDE_DATE=true node server.js # suppress ISO timestamp DEBUG=* DEBUG_COLORS=false node server.js # no ANSI colors DEBUG=* DEBUG_DEPTH=5 node server.js # util.inspect depth DEBUG=* DEBUG_SHOW_HIDDEN=true node server.js # show hidden properties # Combined DEBUG=app:* DEBUG_HIDE_DATE=1 DEBUG_DEPTH=3 node server.js ``` -------------------------------- ### Environment Variables (Node.js) Source: https://context7.com/debug-js/debug/llms.txt Configuration options for debug behavior in Node.js environments using environment variables, such as enabling namespaces, hiding dates, disabling colors, and setting output depth. ```APIDOC ## Environment Variables (Node.js) Configure debug behavior without code changes via environment variables. ```bash # Enable namespaces DEBUG=app:* node server.js DEBUG=app:http,app:db node server.js DEBUG=*,-connect:* node server.js # all except connect:* # Windows CMD set DEBUG=app:* & node server.js # Windows PowerShell $env:DEBUG='app:*'; node server.js # Tune output detail DEBUG=* DEBUG_HIDE_DATE=true node server.js # suppress ISO timestamp DEBUG=* DEBUG_COLORS=false node server.js # no ANSI colors DEBUG=* DEBUG_DEPTH=5 node server.js # util.inspect depth DEBUG=* DEBUG_SHOW_HIDDEN=true node server.js # show hidden properties # Combined DEBUG=app:* DEBUG_HIDE_DATE=1 DEBUG_DEPTH=3 node server.js ``` ``` -------------------------------- ### Temporarily Disable and Re-enable Debug Source: https://github.com/debug-js/debug/blob/master/README.md Shows how to temporarily disable all debug namespaces using `debug.disable()` and then restore the previous state by passing the returned namespaces to `debug.enable()`. ```javascript let debug = require('debug'); debug.enable('foo:*,-foo:bar'); let namespaces = debug.disable(); debug.enable(namespaces); ``` -------------------------------- ### Enable Debug Colors in Child Processes Source: https://github.com/debug-js/debug/blob/master/README.md Configure child processes to display debug colors by setting the `DEBUG_COLORS` environment variable to `1`. This is necessary when `stderr` is piped. ```javascript worker = fork(WORKER_WRAP_PATH, [workerPath], { stdio: [ /* stdin: */ 0, /* stdout: */ 'pipe', /* stderr: */ 'pipe', 'ipc', ], env: Object.assign({}, process.env, { DEBUG_COLORS: 1 // without this settings, colors won't be shown }), }); worker.stderr.pipe(process.stderr, { end: false }); ``` -------------------------------- ### npm script for Windows debug Source: https://github.com/debug-js/debug/blob/master/README.md Define an npm script to set the DEBUG environment variable and run the Node.js application using PowerShell. ```javascript "windowsDebug": "@powershell -Command $env:DEBUG='*';node app.js" ``` -------------------------------- ### Extend Debug Namespace Source: https://context7.com/debug-js/debug/llms.txt Create child namespaces from a parent instance using `extend`. The child inherits the parent's custom log function. You can specify a custom delimiter or use an empty string for no delimiter. ```javascript const debug = require('debug'); const authLog = debug('auth'); authLog.log = console.log.bind(console); // redirect to stdout const signLog = authLog.extend('sign'); // namespace: 'auth:sign' const loginLog = authLog.extend('login'); // namespace: 'auth:login' const rawLog = authLog.extend('raw', ''); // namespace: 'authraw' (empty delimiter) debug.enable('auth:*'); authLog('initialized'); // auth initialized +0ms signLog('token issued'); // auth:sign token issued +0ms loginLog('user logged in'); // auth:login user logged in +1ms // Custom delimiter example const httpLog = debug('http'); const getLog = httpLog.extend('GET', ' '); // namespace: 'http GET' debug.enable('http GET'); getLog('/api/users'); ``` -------------------------------- ### Extend Debugger Namespace Source: https://github.com/debug-js/debug/blob/master/README.md Create new debug instances with extended namespaces using the `extend` method. This is useful for organizing related debug logs. ```javascript const log = require('debug')('auth'); //creates new debug instance with extended namespace const logSign = log.extend('sign'); const logLogin = log.extend('login'); log('hello'); // auth hello logSign('hello'); //auth:sign hello logLogin('hello'); //auth:login hello ``` -------------------------------- ### Check if Debug Target is Enabled Source: https://github.com/debug-js/debug/blob/master/README.md Create a debug instance and check its `enabled` property to determine if it is currently active. This property can also be manually toggled. ```javascript const debug = require('debug')('http'); if (debug.enabled) { // do stuff... } ``` -------------------------------- ### Configure Debug Output Stream to stdout Source: https://github.com/debug-js/debug/blob/master/README.md Override the default stderr output stream for specific debug namespaces or all namespaces. Ensure to bind `console.log` or `console.info`. ```javascript var debug = require('debug'); var error = debug('app:error'); // by default stderr is used error('goes to stderr!'); var log = debug('app:log'); // set this namespace to log via console.log log.log = console.log.bind(console); // don't forget to bind to console! log('goes to stdout'); error('still goes to stderr!'); // set all output to go via console.info // overrides all per-namespace log settings debug.log = console.info.bind(console); error('now goes to stdout via console.info'); log('still goes to stdout, but via console.info now'); ``` -------------------------------- ### debugInstance.log Source: https://context7.com/debug-js/debug/llms.txt Allows overriding the output function for a specific debug instance or globally for all instances. By default, debug output goes to `process.stderr` or `console.debug`. ```APIDOC ## `debugInstance.log` — Override the output function per instance By default every debug instance writes to `process.stderr` (Node.js) or `console.debug` (browser). Override the `log` property on any instance, or on the `debug` factory itself, to redirect output. ```js const debug = require('debug'); const errorLog = debug('app:error'); const infoLog = debug('app:info'); debug.enable('app:*'); // Default: both go to stderr errorLog('something went wrong'); // Redirect a single instance to stdout infoLog.log = console.log.bind(console); infoLog('server started on port 3000'); // goes to stdout // Redirect ALL instances globally (overrides per-instance settings) debug.log = console.info.bind(console); errorLog('now also goes to stdout via console.info'); infoLog('still stdout, but via console.info now'); // In a child process — preserve colors through piped stderr const { fork } = require('child_process'); const worker = fork('./worker.js', [], { stdio: [0, 'pipe', 'pipe', 'ipc'], env: { ...process.env, DEBUG_COLORS: '1' } }); worker.stderr.pipe(process.stderr, { end: false }); ``` ``` -------------------------------- ### debug(namespace) — Create a namespaced debug logger Source: https://context7.com/debug-js/debug/llms.txt Returns a function that logs messages tagged with `namespace` when that namespace is enabled. The returned function accepts printf-style format strings and any number of additional arguments. ```APIDOC ## debug(namespace) ### Description Creates a scoped logger function for a specific namespace. This function logs messages only when its corresponding namespace is enabled. ### Parameters #### namespace - **namespace** (string) - Required - The name of the debug namespace (e.g., 'app:http'). ### Usage ```javascript const debug = require('debug'); const httpLog = debug('app:http'); httpLog('GET %s %d', '/users', 200); // Output: app:http GET /users 200 +0ms (if enabled) ``` ### Enabling Namespaces Namespaces can be enabled using `debug.enable()` or the `DEBUG` environment variable. ```javascript // Enable specific namespaces debug.enable('app:http,app:db'); // Enable all namespaces under 'app:*' // DEBUG=app:* node app.js ``` ``` -------------------------------- ### Checking Debug Target Enabled Status Source: https://github.com/debug-js/debug/blob/master/README.md Explains how to check if a specific debug target is enabled using the `enabled` property. ```APIDOC ## debug.enabled ### Description Provides a boolean value indicating whether the debug target is currently enabled. This property can also be manually toggled to force the debug instance to be enabled or disabled. ### Usage ```javascript const debug = require('debug')('http'); if (debug.enabled) { // do stuff... } ``` ### Property - **enabled** (boolean) - Read/Write - Indicates if the debug target is enabled. ``` -------------------------------- ### debugInstance.enabled Source: https://context7.com/debug-js/debug/llms.txt A property that allows manually forcing the enabled or disabled state of a specific debug instance, overriding the global namespace-based enable/disable settings. ```APIDOC ## `debugInstance.enabled` (property) — Manually force enable/disable The `enabled` getter/setter on each debug instance allows hard-overriding the namespace-based enable state for that specific instance, independent of any global `enable()`/`disable()` calls. ```js const debug = require('debug'); const log = debug('service:worker'); // Globally disabled console.log(log.enabled); // false // Force-enable this single instance log.enabled = true; log('this will print even though namespace is not enabled'); // Force-disable despite matching namespace debug.enable('service:*'); log.enabled = false; log('this will NOT print'); // Reset to namespace-driven behavior by restoring via enable log.enabled = undefined; // clears override; falls back to namespace matching // or simply: debug.enable(debug.disable()); // re-enables all previously active namespaces console.log(log.enabled); // true (matches 'service:*') ``` ``` -------------------------------- ### Add Custom Debug Formatters Source: https://context7.com/debug-js/debug/llms.txt Extend `debug.formatters` to add new printf-style format specifiers for custom output. The formatter function receives the argument value and must return a string. ```javascript const createDebug = require('debug'); // Add %h formatter: renders a Buffer as a hex string createDebug.formatters.h = v => v.toString('hex'); // Add %b formatter: renders a value as a binary string createDebug.formatters.b = v => (v >>> 0).toString(2); const log = createDebug('crypto:util'); createDebug.enable('crypto:util'); const buf = Buffer.from('hello'); log('raw bytes: %h', buf); // => crypto:util raw bytes: 68656c6c6f +0ms log('flags: %b', 0b10110101); // => crypto:util flags: 10110101 +0ms // Built-in formatters (always available) log('%O', { a: { b: { c: 1 } } }); // multi-line util.inspect log('%o', { a: { b: { c: 1 } } }); // single-line util.inspect log('%j', { key: 'val' }); // JSON.stringify (browser only) log('%s %d', 'count:', 42); // string + number log('100%%'); // literal % ``` -------------------------------- ### Manually Force Debug Instance Enable/Disable Source: https://context7.com/debug-js/debug/llms.txt Use the `enabled` property on a debug instance to manually override its enable state, independent of global settings. Set to `true` to force enable, `false` to force disable, or `undefined` to revert to namespace-based behavior. ```javascript const debug = require('debug'); const log = debug('service:worker'); // Globally disabled console.log(log.enabled); // false // Force-enable this single instance log.enabled = true; log('this will print even though namespace is not enabled'); // Force-disable despite matching namespace debug.enable('service:*'); log.enabled = false; log('this will NOT print'); // Reset to namespace-driven behavior by restoring via enable log.enabled = undefined; // clears override; falls back to namespace matching // or simply: debug.enable(debug.disable()); // re-enables all previously active namespaces console.log(log.enabled); // true (matches 'service:*') ``` -------------------------------- ### debug.enabled(name) — Check if a namespace is currently active Source: https://context7.com/debug-js/debug/llms.txt Returns `true` if the given namespace string matches the currently enabled set (honoring wildcards and exclusions). Useful for guarding expensive computations. ```APIDOC ## debug.enabled(name) ### Description Checks if a given namespace is currently active based on the enabled set, respecting wildcards and exclusions. This is useful for conditionally executing code only when debugging is active. ### Parameters #### name - **name** (string) - Required - The namespace to check. ### Returns - **boolean** - `true` if the namespace is enabled, `false` otherwise. ### Usage ```javascript const debug = require('debug'); debug.enable('app:*,-app:verbose'); console.log(debug.enabled('app:http')); // true console.log(debug.enabled('app:verbose')); // false (excluded) console.log(debug.enabled('worker:task')); // false (not matched) // Per-instance check via the .enabled property const log = debug('app:http'); if (log.enabled) { // This code only runs if 'app:http' is enabled const payload = JSON.stringify(expensiveSerialize()); log('payload: %s', payload); } ``` ``` -------------------------------- ### debug.formatters Source: https://context7.com/debug-js/debug/llms.txt Extends the library's formatting capabilities by adding custom printf-style format specifiers. New formatters are added as single-letter keys to `debug.formatters`. ```APIDOC ## `debug.formatters` — Add custom printf-style format specifiers Extend `debug.formatters` with single-letter keys to define custom `%x` format tokens. The formatter function receives the corresponding argument value and must return a string. ```js const createDebug = require('debug'); // Add %h formatter: renders a Buffer as a hex string createDebug.formatters.h = v => v.toString('hex'); // Add %b formatter: renders a value as a binary string createDebug.formatters.b = v => (v >>> 0).toString(2); const log = createDebug('crypto:util'); createDebug.enable('crypto:util'); const buf = Buffer.from('hello'); log('raw bytes: %h', buf); // => crypto:util raw bytes: 68656c6c6f +0ms log('flags: %b', 0b10110101); // => crypto:util flags: 10110101 +0ms // Built-in formatters (always available) log('%O', { a: { b: { c: 1 } } }); // multi-line util.inspect log('%o', { a: { b: { c: 1 } } }); // single-line util.inspect log('%j', { key: 'val' }); // JSON.stringify (browser only) log('%s %d', 'count:', 42); // string + number log('100%%'); // literal % ``` ``` -------------------------------- ### Override Debug Instance Log Output Source: https://context7.com/debug-js/debug/llms.txt Redirect output from a specific debug instance or globally for all instances by overriding the `log` property. This is useful for sending logs to different streams or consoles. ```javascript const debug = require('debug'); const errorLog = debug('app:error'); const infoLog = debug('app:info'); debug.enable('app:*'); // Default: both go to stderr errorLog('something went wrong'); // Redirect a single instance to stdout infoLog.log = console.log.bind(console); infoLog('server started on port 3000'); // goes to stdout // Redirect ALL instances globally (overrides per-instance settings) debug.log = console.info.bind(console); errorLog('now also goes to stdout via console.info'); infoLog('still stdout, but via console.info now'); // In a child process — preserve colors through piped stderr const { fork } = require('child_process'); const worker = fork('./worker.js', [], { stdio: [0, 'pipe', 'pipe', 'ipc'], env: { ...process.env, DEBUG_COLORS: '1' } }); worker.stderr.pipe(process.stderr, { end: false }); ``` -------------------------------- ### debug.disable() — Disable all namespaces and return current set Source: https://context7.com/debug-js/debug/llms.txt Disables all active debug namespaces and returns the previous namespace string. This is useful for temporarily suppressing output and restoring it later. ```APIDOC ## debug.disable() ### Description Disables all currently active debug namespaces and returns the string representing the previously enabled namespaces. This allows for saving and restoring the debug state. ### Returns - **string** - The string representing the previously enabled namespaces. ### Usage ```javascript const debug = require('debug'); debug.enable('foo:*,-foo:bar'); // Capture current state before disabling const snapshot = debug.disable(); console.log(snapshot); // 'foo:*,-foo:bar' // All debug output is now suppressed const log = debug('foo:baz'); console.log(log.enabled); // false // Restore later debug.enable(snapshot); console.log(debug('foo:baz').enabled); // true ``` ``` -------------------------------- ### Check if a Namespace is Active Source: https://context7.com/debug-js/debug/llms.txt Returns true if the given namespace string matches the currently enabled set, honoring wildcards and exclusions. Useful for guarding expensive computations. ```javascript const debug = require('debug'); debug.enable('app:*,-app:verbose'); console.log(debug.enabled('app:http')); // true console.log(debug.enabled('app:verbose')); // false (excluded) console.log(debug.enabled('worker:task')); // false (not matched) console.log(debug.enabled('app:anything')); // true (matched by app:*) // Per-instance check via the .enabled property const log = debug('app:http'); if (log.enabled) { const payload = JSON.stringify(expensiveSerialize()); // only runs if enabled log('payload: %s', payload); } ``` -------------------------------- ### Disable All Debug Namespaces Source: https://context7.com/debug-js/debug/llms.txt Disables all active debug namespaces and returns the previous namespace string. Useful for temporarily suppressing output and restoring it later. ```javascript const debug = require('debug'); debug.enable('foo:*,-foo:bar'); // Capture current state before disabling const snapshot = debug.disable(); console.log(snapshot); // 'foo:*,-foo:bar' // All debug output is now suppressed const log = debug('foo:baz'); console.log(log.enabled); // false // Restore later debug.enable(snapshot); console.log(debug('foo:baz').enabled); // true ``` -------------------------------- ### Dynamically Enable/Disable Debug Namespaces in Browser Source: https://context7.com/debug-js/debug/llms.txt Programmatically enable or disable debug namespaces within your browser application code. This allows for runtime control over which debug messages are displayed. ```javascript debug.enable('worker:a'); debug.disable(); ``` -------------------------------- ### Set localStorage.debug in Browser DevTools Source: https://context7.com/debug-js/debug/llms.txt Set localStorage.debug in the browser's DevTools console to enable specific debug namespaces. This setting persists across page reloads. ```javascript localStorage.debug = 'worker:*'; ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.