Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/aiteq/trace
TypeScript decorator to trace method calls using https://github.com/visionmedia/debug
https://github.com/aiteq/trace
debug logging trace typescript
Last synced: 3 months ago
JSON representation
TypeScript decorator to trace method calls using https://github.com/visionmedia/debug
- Host: GitHub
- URL: https://github.com/aiteq/trace
- Owner: aiteq
- License: mit
- Created: 2017-06-02T20:53:09.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-06-03T19:45:29.000Z (over 7 years ago)
- Last Synced: 2024-11-14T11:44:10.336Z (3 months ago)
- Topics: debug, logging, trace, typescript
- Language: TypeScript
- Size: 6.84 KB
- Stars: 7
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# trace
[![Build Status](https://travis-ci.org/aiteq/trace.svg?branch=master)](https://travis-ci.org/aiteq/trace)TypeScript decorator to trace method calls using https://github.com/visionmedia/debug
## Installation
```bash
$ npm install @aiteq/trace
```## Usage
The `Trace` decorator can be used for classes as well as for methods.### Decorating a class:
```ts
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.jsTRACE => User.toString() +0ms
TRACE => User.getName() +5ms
TRACE <= User.getName: Honza +6ms
TRACE <= User.toString: Honza +7ms
Honza
```### Decorating a method:
```ts
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.jsTRACE => User.getName() +0ms
TRACE <= User.getName: Honza +5ms
Honza
```### Notes
- While [decorators](https://www.typescriptlang.org/docs/handbook/decorators.html) are still experimental, you must set `experimentalDecorators` to `true` in your `tsconfig.json`.
- The output is controlled by the `DEBUG` environment variable. All tracing records are prefixed with the `TRACE` string. So for enabling the tracing set the `DEBUG` variable to e.g. `TRACE` or `*`. See `debug`'s [doc](https://github.com/visionmedia/debug) for details.
- The output will be colorized by `debug`.
- Tracing doesn't work for constructors.