uconsole
Hook, namespace, and shim console for the browser and node.js
- Hook console methods while preserving line number
- Create namespaced consoles and filter logging using a pattern
- Shim console for environments where it is not provided.
- Works in the browser or node.js
Installation
Install using npm:
npm install uconsole
Install using bower:
bower install uconsole
Using browser script tag and global (UMD wrapper):
// Available via window.uconsole
Usage
uconsole
does not patch the global console on load. Instead, replace the
global console manually using patch()
:
uconsole;
API Reference
Members
uconsole.namespace(namespace)
Create a namespaced console.
Params
- namespace
String
Returns: console
- returns namespaced console
Example
var debug = console; debug;
Filter namespaced console logs by providing a pattern using localStorage
in
the browser or the DEBUG
environment variable for node.js:
localStorage;
DEBUG=mymodule
You can match multiple namespaces by separating them with a comma:
DEBUG=mymodule,anothermodule
Or use wildcards:
DEBUG=server:*
would match both server:request
and server:response
namespaces:
uconsole.patch(console)
Patch given console
with uconsole methods.
Params
- console
Object
Returns: Object
Example
uconsole;
uconsole.use(hook)
Hook console methods and run your own functions.
Params
- hook
function
Returns: console
Example
console;
Contributing
Please submit all issues and pull requests to the alexmingoia/uconsole repository!
Tasks
List available tasks with gulp help
.
Tests
Run tests using npm test
or gulp test
.
Support
If you have any problem or suggestion please open an issue here.