The module in JavaScript provides convenient, layered, logging into data structure. Logger writes messages( incoming & outgoing ) to data structure( array of arrays ) specified by( outputData ). Each inner array represent new level of the structure. On write logger puts messages into structure level which is equal to logger level property value. Creates folders if needed level does not exist logger it. Next level is always placed at zero index of previous.Then transfers message to the next output(s) object in the chain if it exists.
npm install wLoggerToJstructure
- outputData { array }[ optional ] - structure where to write messages, creates own structure by default.
- output { object }[ optional ] - single output object for current logger, null by default.
Output:
- log
- error
- info
- warn
Leveling:
Chaining:
- Add object to output list - outputTo
- Remove object from output list - outputUnchain
- Add current logger to target's output list - inputFrom
- Remove current logger from target's output list - inputUnchain
Other:
- Check if object exists in logger's inputs list - hasInput
- Check if object exists in logger's outputs list - hasOutput
- Convert data structure to json string - toJson
/* Simple example */
var data = [];
var l = new wLoggerToJstructure();
/* Increase current level( 0 ) by 2 */
l.log( 'x' );
l.up( 2 );
l.log( 'aa\nbb' );
console.log( l.outputData );
/*
[
'x',
[
[ 'aa\nbb' ]
]
]
*/
/* console as input to store it into arrays */
var l = new wLoggerToJstructure();
l.inputFrom( console );
/* Increase current level by 1 */
l.up( 1 );
console.log( 'aabb' );
console.log( l.toJson() );
/* record console output */
/*
[
[ 'aabb' ]
]
*/
/* another logger as output */
var logger = new wLogger();
var l = new wLoggerToJstructure
({
output : logger
});
l.log( 'abc' );
/* logger prints
abc
*/