Javascript utility for automatic logging of functions and classes.
$ npm install autologger --save
const Autolog = require('autologger');
const autolog = Autolog(options)(type)(logger);
let target = autolog(target);
Variable | Type | Required |
---|---|---|
options | object | no |
type | string | yes |
logger | object | yes |
target | function or class | yes |
Logs the wrapping of a variable by an automatic logger. Must contain two properties:
Properties | Type | Required |
---|---|---|
preprocess | function | no |
postprocess | function | no |
The type of the variable to which automatic logging is applied. One of the following values:
- class
- function
- method
Logs the call steps. Must contain two properties:
Properties | Type | Required |
---|---|---|
before | function | yes |
after | function | yes |
The function or class to which automatic logging will be applied.
const logger = {
before: console.log,
after: console.log,
};
const autolog = Autolog()('function')(logger);
let example = autolog(function example() { /* ... */ });
const autolog = Autolog()('class')(logger);
let Example = autolog(class Example {
/* ... */
});
const autolog = Autolog()('class')(logger);
@autolog
class Example {
/* ... */
}
const autolog = Autolog()('method')(logger);
class Example {
@autolog
test() { /* ... */ }
}
This project is licensed under MIT.