Simple debug logger for Browser and Node.js.
- Provide a single
debug
function - Add caller's file name as prefix to log using StackTracey
- Support TypeScript
- Support ES modules
import
- Support Browser and Node.js
This library is inspired by visionmedia/debug.
Install with npm:
npm install @deps/debug
This library provide a debug
function.
This debug
function output to console if DEBUG MODE is enabled.
import { debug } from "@deps/debug";
debug("log text"):
// => Output to console: "log text"
Tips 💡
@deps/debug
also provide debug
function as debugLog
.
debugLog
is a just alias to debug
function.
You can use debugLog
to avoid conflict naming with Node.js's utils
, visionmedia/debug, or other modules.
import { debugLog } from "@deps/debug";
debugLog("log text"):
// => Output to console: "log text"
debug
accept following values as DEBUG.
*
: Enable all debug logprefix:*
Enable debug log that start withprefix:
-prefix:*
Disable debug log that start withprefix:
Also, debug
accept Multiple values as DEBUG.
The values should be separated by ,
.
a,b,c
Enable DEBUG MODE by Environment Variables.
DEBUG=*
DEBUG=prefix:*
DEBUG=-prefix:*
DEBUG=-p1,p2,p3
Notes: Node.js add file name as prefix automatically.
When you specify DEBUG=*/your-file.js
, this library output log that file name is your-file.js
.
// src/your-file.js
import { debug } from "@deps/debug";
debug("log text"):
// => "src/your-file.js: log text"
debug("log text");
// => No output
Enable DEBUG MODE by localStorage
API.
localStorage.debug = '*';
localStorage.debug = 'prefix:*'
localStorage.debug = '-prefix:*'
localStorage.debug = 'p1,p2,p3'
DEBUG_CONTROLLER
is shared value of the debug
module.
import { DEBUG_CONTROLLER } from "@deps/debug"
// Stop logging
DEBUG_CONTROLLER.disable();
// Start logging(by default)
DEBUG_CONTROLLER.enable();
Also you can force enable. This ignore -prefix
pattern.
import { DEBUG_CONTROLLER } from "@deps/debug"
DEBUG_CONTROLLER.forceEnable();
See Releases page.
Install devDependencies and Run npm test
:
npm i -d && npm test
Pull requests and stars are always welcome.
For bugs and feature requests, please create an issue.
- Fork it!
- Create your feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- Submit a pull request :D
MIT © azu
Some codes are copied from following:
- visionmedia/debug
- Copyright (c) 2014-2017 TJ Holowaychuk [email protected]