custom-log
A tiny (~2kb) flexible logger, very basic, simple and fast. Will add some features over time.
custom-log is targeted at the Browser as a tiny helper that makes available any custom log function you can create yourself, and which can be enabled/disabled individually.
Although there are plenty full-fledged loggers for use in node, you can use this one instead if you don't need a zillion features but rather prefer simplicity.
How to use?
First install:
Browser: <script src="./custom-log.min.js"></script>
Node: npm install --save custom-log
<function> customLog( <string>/<object> init )
Returns a log function based on the init argument. The init argument can be either a string or an object.
If init is a string, only the base log function's prefix can be set with a string. In case init is an
object, multiple custom log functions with their own prefix strings can be defined in the init object.
To set the base log function prefix in a init object, use the reserved 'log' key. See some examples below:
const customLog= require( 'custom-log' );
const log= customLog();
log( 'hey!' );
const settings = {
silentDisable : false
silentEnable : false
};
const log= customLog({
info : 'INFO: ',
warning : 'WARNING: ',
error : 'ERROR: ',
listener : 'LISTENER: ',
dal : 'DAL: '
time : () => new Date()
}, settings );
log( 'hello' );
log.info( 'easy!' );
log.dal( 'Success! Payload: ', 'some payload' );
log.dal.disable();
log.dal.enable();
log.disable( 'dal listener error log' );
log.enable( 'error', 'listener', 'log' );
log.enable( ['error', 'listener', 'log'] );
change log
0.3.0
- removes log.assert
- adds dynamic function prefix
- adds 'silentEnable' and 'silentDisable' initialization modes
0.2.3
- removes leading space for default log without prefix
- log.assert is way too naive and you better use something like the 'assert' npm lib for that. log.assert is now deprecated and will be removed over time.
0.2.1
changes license to MIT
0.1.9
Fixed bug that caused a crash on using the disable or enable function
0.1.6
Added log.assert function
0.1.0
Initial commit.
###license
MIT