Tiny namespaced debug logging for Node.js and the browser, switched on with DEBUG
open sourceMITfree
debug is a small JavaScript debugging utility modelled on the technique Node.js core uses. Each module creates a namespaced logger, and the DEBUG environment variable (or localStorage.debug in the browser) turns output on for chosen namespaces, with wildcards and exclusions. Each namespace gets its own colour, lines show the milliseconds since the last message, printf-style formatters print objects, and output can go to another stream or a custom log function. It works in Node.js and web browsers.
Problems it solves
- turn on debug output for one part of my Node.js app without changing code
- add debug logging to an npm library that stays silent by default
- see timing between log lines while debugging a Node.js service
Features
- Namespaced loggers turned on with the DEBUG environment variable
- Wildcards and exclusions, such as DEBUG=worker:*,-worker:b
- A colour per namespace and the time since the last message
- printf-style formatters, with custom ones
- Works in Node.js and in browsers (localStorage.debug)
- Enable, disable or extend namespaces at runtime
Alternatives
The same job
These do what debug does.
- Pino Super fast, all natural JSON logger for Node.js