2.10.0 • Published 11 months ago

log-execution-time-new v2.10.0

Weekly downloads
-
License
ISC
Repository
github
Last release
11 months ago

Log Method Execution Time Decorator

A simple TypeScript decorator for logging the execution time of methods. This package helps in measuring and logging the time taken by methods to execute, useful for performance monitoring and debugging.

Installation

To install the package, run:

npm install log-execution-time-new

Basic Example

Use the decorator on a synchronous method:

import LogExecutionTime from 'log-execution-time-new';

class ExampleClass {
  @LogExecutionTime()
  myMethod() {
    // Simulate a time-consuming task
    for (let i = 0; i < 1e6; i++) {}
  }
}

const instance = new ExampleClass();
instance.myMethod();
Expected Output: 2024-07-26T14:28:00.000Z myMethod: 123ms

Use the decorator on an asynchronous method:

import LogExecutionTime from 'log-execution-time-new';

class ExampleClass {
  @LogExecutionTime()
  async myAsyncMethod() {
    // Simulate a time-consuming task
    return new Promise(resolve => setTimeout(resolve, 1000));
  }
}

const instance = new ExampleClass();
instance.myMethod();
Expected Output: 2024-07-26T14:29:00.000Z myAsyncMethod: 1000ms

Additional Parameters

  1. Options: Provide options that will be used while logging the execution time:
import LogExecutionTime from 'log-execution-time-new';

class ExampleClass {
  @LogExecutionTime({ keyName: "CustomKeyMethod" })
  myCustomKeyMethod() {
    // Simulate a time-consuming task
    for (let i = 0; i < 1e6; i++) {}
  }
}

const instance = new ExampleClass();
instance.myCustomKeyMethod();
Expected Output: 2024-07-26T14:30:00.000Z CustomKeyMethod: 200ms

Available Options

  1. keyName: Set custom key for the logged entity.
  2. disable: Conditionally disable logging.
  3. showExecutionCount: Add a count for how many times a function being called.

Contributing

Feel free to submit issues or pull requests if you have suggestions for improvements or find bugs.

License

This package is licensed under the ISC License

2.10.0

11 months ago

2.9.12

11 months ago

2.9.11

12 months ago

2.9.10

12 months ago

2.9.9

12 months ago

2.9.8

12 months ago

2.9.7

12 months ago

2.9.6

12 months ago

2.8.6

12 months ago

2.7.6

12 months ago

2.6.6

12 months ago

2.5.6

12 months ago

2.4.6

12 months ago

2.3.6

12 months ago

2.3.5

12 months ago

2.2.5

12 months ago

2.1.5

12 months ago

2.1.3

12 months ago

2.1.2

12 months ago

1.1.2

12 months ago

1.1.1

12 months ago

1.0.1

12 months ago

1.0.0

12 months ago