1.0.0 • Published 6 years ago

autologger v1.0.0

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

autologger

Javascript utility for automatic logging of functions and classes.

Install

$ npm install autologger --save

Usage

const Autolog = require('autologger');

const autolog = Autolog(options)(type)(logger);

let target = autolog(target);
VariableTypeRequired
optionsobjectno
typestringyes
loggerobjectyes
targetfunction or classyes

options

Logs the wrapping of a variable by an automatic logger. Must contain two properties:

PropertiesTypeRequired
preprocessfunctionno
postprocessfunctionno

type

The type of the variable to which automatic logging is applied. One of the following values:

  • class
  • function
  • method

logger

Logs the call steps. Must contain two properties:

PropertiesTypeRequired
beforefunctionyes
afterfunctionyes

target

The function or class to which automatic logging will be applied.

Example

Logger

const logger = {
    before: console.log,
    after: console.log,
};

Function

const autolog = Autolog()('function')(logger);

let example = autolog(function example() { /* ... */ });

Class

const autolog = Autolog()('class')(logger);

let Example = autolog(class Example {
    /* ... */
});

with decorators

see js decorators

const autolog = Autolog()('class')(logger);

@autolog
class Example {
    /* ... */
}

Class method

const autolog = Autolog()('method')(logger);

class Example {
    @autolog
    test() { /* ... */ }
}

License

This project is licensed under MIT.