npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

method-log-decorator

v1.0.4

Published

A lightweight TypeScript library providing easy-to-use logging decorators.

Downloads

2

Readme

method-log-decorator

A lightweight TypeScript library providing easy-to-use logging decorators for your methods.
Make your code more compact and gain extended logging abilities with minimal effort. Can log inputs, outputs, execution time and more.

https://github.com/refined/ts_log_decorator

Features

  • Method decorators for logging input, output, execution time, and exceptions
  • Works with the latest TypeScript (standard ECMAScript decorators)
  • No runtime dependencies
  • Simple API for quick integration

Installation

npm install method-log-decorator

Usage

Argument Names Are Mandatory

TypeScript does not provide function argument names at runtime.
For all decorators that log input arguments
you must explicitly provide the argument names via the arg_names option/parameter.


@log(options)

Logs method input and output with customizable options.

import { log } from "log-decorator";

class Example {
  @log({
    log_input: { arg_names: ["param1", "param2"] }, // <-- argument names are required!
    log_exception: true,
    log_time: true,
  })
  myMethod(param1: string, param2: number) {
    // Your logic here
  }
}

@logCall(argNames, message?)

Logs method call with argument names and an optional message.

import { logCall } from "log-decorator";

class Example {
  @logCall(["userId", "payload"], "User update called") // <-- argument names are required!
  updateUser(userId: string, payload: object) {
    // ...
  }
}

@logException(message?)

Logs exceptions thrown by the method with an optional custom message.

import { logException } from "log-decorator";

class Example {
  @logException("Error in importantMethod")
  importantMethod() {
    throw new Error("Something went wrong!");
  }
}

@logExecutionTime()

Logs the execution time of the method.

import { logExecutionTime } from "log-decorator";

class Example {
  @logExecutionTime()
  slowOperation() {
    // Some slow code
  }
}

@logAnything(options)

Advanced:
logAnything is a low-level decorator factory.
It is recommended to use the wrappers (log, logCall, logException, logExecutionTime) instead for most cases.

Parameters for logAnything(options: LogOptions)

  • message?: string
    Custom log message. If not provided, uses ClassName.methodName.

  • max_arr_len?: number
    Maximum number of array elements to log (default: 10).

  • log_input?: { arg_names: string[] }
    Log input arguments.

    • arg_names: Names for each argument to display in logs (mandatory if logging input).
  • log_output?: boolean
    Log the output/result of the method.

  • log_exception?: boolean
    Log exceptions thrown by the method.

  • log_time?: boolean
    Log the execution time of the method.

Example

import { logAnything } from "log-decorator";

class Example {
  @logAnything({
    message: "Custom log message",
    max_arr_len: 5,
    log_input: { arg_names: ["input1", "input2"] }, // <-- argument names are required!
    log_output: true,
    log_exception: true,
    log_time: true,
  })
  test(input1: number[], input2: string) {
    // ...
  }
}

Tip: For most use cases, prefer the higher-level decorators (log, logCall, logException, logExecutionTime) for simpler and more readable code.


License

ISC


Contributions welcome!