inversify-tracer
Tool that allows the developer to trace methods of objects created by InversifyJS.
Installation
You can get the latest release and the type definitions using npm:
$ npm install --save inversify-tracer
Example
;;; decorateinjectable, Ninja; ; container.bind'Ninja'.toNinja; ; tracer.on'call',; tracer.on'return',; tracer.applycontainer; ; ninja.attack2;ninja.slowAttack4, 1000;
Result:
Ninja attack called with [{"name":"force","value":2}]
Ninja attack returned 64 - 0ms
Ninja slowAttack called with [{"name":"force","value":4},{"name":"time","value":1000}]
Ninja attack called with [{"name":"force","value":4}]
Ninja attack returned 128 - 0ms
Ninja slowAttack returned 128 - 1004ms
Configuration
The configuration allows you to change the default behavior of the tracer. This configuration is passed through the InversifyTracer constructor. Example:
; tracer.applycontainer;
Property | Type | Default | Description |
---|---|---|---|
filters | string[] | ['*:*'] | Filters that choose which classes and method will be traced |
inspectReturnedPromise | boolean | true | Inpect the value from the returned Promise object |
Filters
Filters allow you to specify the classes and/or functions you want to trace. By default, all classes and methods will be traced.
Filter examples:
// trace every class, except Ninja // trace every method of the class Ninja, except the 'hide' method // trace attack method from every class // trace every method of the classes that start with 'Nin'
Events
Event: 'call'
- callInfo <CallInfo>
Emitted each time a class method is called.
CallInfo
Property | Type | Description |
---|---|---|
className | string | Name of the class |
methodName | string | Name of the method |
parameters | Parameter[] | Array with the name of the method's parameters and their value |
Event: 'return'
- returnInfo <ReturnInfo>
Emitted each time a class method ends.
ReturnInfo
Property | Type | Description |
---|---|---|
className | string | Name of the class |
methodName | string | Name of the method |
result | any | Returned value of the method |
executionTime | number | Method execution time in milliseconds |