composite-logger
Lightweight logger composite to help you debug your modules and disable when you go to production
Installation
$ npm install @unic/composite-logger
Importing
import logger from '@unic/composite-logger';
const logger = require('@unic/composite-logger').default;
Usage
Creation
const obj = logger('MyPrefix');
window.localStorage.debug = true;
obj.log('Hello', 'World');
API
logger([prefix])
Create an object with a log method.
Returns: Object
- Returns an object with exposed .log() method
Param | Type | Default | Description |
---|
[prefix] | String | | If given, provides a prefix for the logged content from the log method |
Example
const obj = logger('MyModule');
const obj = logger();
const obj = Object.assign({}, object1, object2, logger('MyModule'));
log([params...])
Log function params to console (including given prefix from creation).
Info: window.localStorage.debug must be truthy to see output in the console
Returns: undefined
Param | Type | Default | Description |
---|
[params...] | Any | Pass any number of arguments you want to log to the console | |
Example
const obj = logger('MyModule');
window.localStorage.debug = true;
obj.log('Hello', 'World', '!');
obj.log(1, 2, 3, 4);
Helpful Information
A composite is a function or an object which can be used as is or to merged with another object. These composites are normally used in the factory/composition pattern.
Helpful Ressources:
License
Apache-2.0