Class methods invocation logging decorator
Description
Decorator for simply and colorful (in Chrome, FF and Node) logging class methods invocation, returned results and possible errors. colors.js is using for Node.
Installation
yarn add cmild
Testing
yarn test:jest # Runs Jest with coverage collection yarn test:coverage # Sends coverage to .coveralls.io yarn test # yarn test:jest && yarn test:coverage
Usage
You may decorate your class with default styles params, which are:
styles: browser: invocation: 'background: #F2EAFF; color: #03A9F4; font-weight: bold' result: 'background: #F2EAFF; color: #4CAF50; font-weight: bold' error: 'background: #F2EAFF; color: #F20404; font-weight: bold' node: invocation: 'bgBlack.blue.bold' result: 'bgBlack.green.bold' error: 'bgBlack.red.bold'
Or set your own styles by passing object as a first argument of decorator, for example:
@
Also you may disable decorator in specific env/build, for example:
@
Common usage:
@Cmild { return testArg } async { return ` ` } { throw this } async { throw await this } const instance = // Frist method invocation and result printingconsole // Second method invocation and result printing when returned promise is resolvedinstance // Third method invocation and error catchingtry instance catch error console // Fourth method invocation and error cathing when returned promise is rejectedinstance