@deps/debug v1.1.0
@deps/debug 
Simple debug logger for Browser and Node.js.
Features
- Provide a single
debugfunction - 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
Install with npm:
npm install @deps/debugUsage
API
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 :bulb:
@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"Enable DEBUG MODE
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
Node.js
Enable DEBUG MODE by Environment Variables.
DEBUG=*
DEBUG=prefix:*
DEBUG=-prefix:*
DEBUG=-p1,p2,p3Notes: 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 outputBrowser
Enable DEBUG MODE by localStorage API.
localStorage.debug = '*';
localStorage.debug = 'prefix:*'
localStorage.debug = '-prefix:*'
localStorage.debug = 'p1,p2,p3'Force disable logging
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();Changelog
See Releases page.
Running tests
Install devDependencies and Run npm test:
npm i -d && npm testContributing
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
Author
License
MIT © azu
Some codes are copied from following:
- visionmedia/debug
- Copyright (c) 2014-2017 TJ Holowaychuk tj@vision-media.ca