It Envolves async/sync methods for automatically logs traces. Inspired in Apex log.
$ npm install acho-trace --save
First load the plugin:
const Acho = require('acho')
Acho = require('acho-trace')(Acho)
Now when you call Acho
for create a new instance, the new instance will have .trace
and .traceSync
methods for envolve functions and create traces.
For see it in action check examples.
The API provides to endpoints:
- acho#trace
- acho#traceSync
both methods follow the same interface:
'use strict'
var Acho = require('acho')
Acho = require('acho-trace')(Acho)
var acho = Acho()
var fn = createFnAsync()
var wrapFnOne = acho.trace(fn, {
/*
OPTIONAL. [default=false]
It expresses if you are wrapping a sync function.
Also you can use `acho#traceSync` endpoint.
*/
sync: false,
/*
OPTIONAL. [default='debug']
output level under non-error result.
*/
level: 'debug',
/*
OPTIONAL. [default='error']
output level under error result.
*/
levelErr: 'error',
/*
OPTIONAL. [default='']
context associated with the message.
*/
context: '',
/*
OPTIONAL.
Custom print function to create print
messages under non-error.
By default it prints the arguments
passed in the original function.
*/
trace: function (obj) {
return ['executed fn with params: %j', obj]
},
/*
OPTIONAL.
Custom print function to create print
messages under error.
By default it prints the arguments
passed in the original function.
*/
traceErr: function (err) {
return ['something bad happens: %s', err.message]
}
})
MIT © Kiko Beats