TypeScript decorator to trace method calls using https://github.com/visionmedia/debug
$ npm install @aiteq/traceThe Trace decorator can be used for classes as well as for methods.
import { Trace } from "@aiteq/trace";
@Trace()
class User {
constructor(public name: string) { }
public getName(): string {
return this.name;
}
public toString(): string {
return this.getName();
}
}
console.log(new User("Honza").toString());The output would look like this:
> DEBUG=* node ./dist/trace-test.js
TRACE => User.toString() +0ms
TRACE => User.getName() +5ms
TRACE <= User.getName: Honza +6ms
TRACE <= User.toString: Honza +7ms
Honza
import { Trace } from "@aiteq/trace";
class User {
constructor(public name: string) { }
@Trace()
public getName(): string {
return this.name;
}
public toString(): string {
return this.getName();
}
}
console.log(new User("Honza").toString());The output would look like this:
> DEBUG=* node ./dist/trace-test.js
TRACE => User.getName() +0ms
TRACE <= User.getName: Honza +5ms
Honza
- While decorators are still experimental, you must set
experimentalDecoratorstotruein yourtsconfig.json. - The output is controlled by the
DEBUGenvironment variable. All tracing records are prefixed with theTRACEstring. So for enabling the tracing set theDEBUGvariable to e.g.TRACEor*. Seedebug's doc for details. - The output will be colorized by
debug. - Tracing doesn't work for constructors.