uconsole
v1.0.2
Published
Hook, namespace, and shim console for the browser and node.js
Readme
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 uconsoleInstall using bower:
bower install uconsoleUsing browser script tag and global (UMD wrapper):
// Available via window.uconsole
<script src="lib/uconsole.js"></script>Usage
uconsole does not patch the global console on load. Instead, replace the
global console manually using patch():
uconsole.patch(console);API Reference
Members
##uconsole.namespace(namespace) Create a namespaced console.
Params
- namespace
String
Returns: console - returns namespaced console
Example
var debug = console.namespace('mymodule');
debug.log('another thing happened');Filter namespaced console logs by providing a pattern using localStorage in
the browser or the DEBUG environment variable for node.js:
localStorage.setItem('debug', 'mymodule');DEBUG=mymoduleYou can match multiple namespaces by separating them with a comma:
DEBUG=mymodule,anothermoduleOr 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.patch(window.console);##uconsole.use(hook) Hook console methods and run your own functions.
Params
- hook
function
Returns: console
Example
console.use(function (namespace, method, message) {
// ... persist log message to elasticsearch ...
});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.
