# nestjs-logtime-decorator

> Typescript decorator to log the duration of a method, for NestJs.

Latest version **1.1.2** (published 2023-08-18) · ISC license · 0 weekly downloads

## Install

```sh
npm install nestjs-logtime-decorator
pnpm add nestjs-logtime-decorator
yarn add nestjs-logtime-decorator
bun add nestjs-logtime-decorator
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.2 |
| Published | 2023-08-18 |
| First published | 2023-06-27 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=16.0.0 |
| Dependencies | 0 |
| Unpacked size | 13.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Maintainers | pleymor |
| Keywords | Typescript, NestJS, Log, Time |

## Links

- npm: https://www.npmjs.com/package/nestjs-logtime-decorator
- Repository: https://github.com/pleymor/nestjs-logtime-decorator
- Homepage: https://github.com/pleymor/nestjs-logtime-decorator#readme
- Issues: https://github.com/pleymor/nestjs-logtime-decorator/issues
- npm.io page: https://npm.io/package/nestjs-logtime-decorator

## Alternatives

- [cli-color](https://npm.io/package/cli-color.md) — 3.4M weekly downloads
- [log](https://npm.io/package/log.md) — 1.3M weekly downloads
- [logstash-client](https://npm.io/package/logstash-client.md) — 4.5K weekly downloads
- [@nocobase/plugin-logger](https://npm.io/package/@nocobase/plugin-logger.md) — 2.0K weekly downloads
- [child-process-debug](https://npm.io/package/child-process-debug.md) — 695 weekly downloads

## Recent versions

- 1.1.2 (latest) — 2023-08-18
- 1.1.1 — 2023-08-18
- 1.1.0 — 2023-08-18
- 1.0.2 — 2023-06-27
- 1.0.1 — 2023-06-27
- 1.0.0 — 2023-06-27

## README

# nestjs-logtime-decorator
Typescript decorator to log the duration of a method, for NestJs.

## Installation

Install the dependency with:

```sh
npm install nestjs-logtime-decorator
```

## Usage

```ts
import { Body, Controller, Post } from '@nestjs/common';
import { MeasureTimeAsync } from 'nestjs-logtime-decorator';
import { MyResourceService } from './my-resource.service';
import { MyResourceDto } from './dto/my-resource.dto';
import { MyResource } from '@prisma/client';

@Controller('my-resource')
export class MyResourceController {
  @Post()
  @MeasureTimeAsync({ context: [
    { key: 'name', from: 'Request' },
    { key: 'id', from: 'Response' }
  ] })
  async createOne(
    @Body() dto: MyResourceDto,
  ): Promise<MyResource> {
    return this.service.createOne(dto);
  }

  @Get('something')
  @MeasureTime()
  getSomethingSync(): string {
    return this.service.getSomethingSync();
  }
}
```

If POST my-resource is called, it will print:
> [Nest] 24377  - 06/26/2023, 10:52:35 PM     LOG [MyResourceController] [name: foo, id: 1] createOne took 97ms

If GET my-resource/something is called, it will print:
> [Nest] 24377  - 06/26/2023, 10:52:37 PM     LOG [MyResourceController] getSomethingSync took 10ms

If GET my-resource/something is called but throws an error, it will print:
> [Nest] 24377  - 06/26/2023, 10:52:37 PM     LOG [MyResourceController] getSomethingSync (error) took 10ms

---
_Source: https://npm.io/package/nestjs-logtime-decorator · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
