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 🙏

© 2025 – Pkg Stats / Ryan Hefner

method-logger

v1.1.0

Published

Adds logs for object/class methods

Downloads

6

Readme

method-logger

Pattern based logger for object/class methods

You can simply trace which function is called and what is passed.

With this you can easy add logs for all object/class methods.

Uses js Proxy.

Usage

For now every method can have only one logger.

Simplest case

By default wraps all methods in object or class.

const logify = require('method-logger')

testObj = logify(testObj);

General objects

const logify = require('method-logger')

let testObj = {
    fn: (a)=>a,
    fn2: (a, b)=>a + b,
    fn3: (a, b)=>{throw new Error('error name')},
    prop: 1,
    strProp: 'prop',
    objProp: {},
};

let proxyLoggerConfig = {
    props: [{
        namePattern: 'fn.*'
    }],
    logger: (target, thisArg, argumentsList) => {console.log(target, argumentsList) }
};

testObj = logify(testObj, proxyLoggerConfig);

testObj.fn(1)           // stdout >> [Function: fn] [ 1 ]
testObj.fn2(1, 2)       // stdout >> [Function: fn2] [ 1, 2 ]
testObj.fn3()           // stdout >> [Function: fn3] []

Classes

Module tries to recognise is this class or object by comparing constructor to string [Function: Object]. This should work in most cases, but you can specify that it is class by manually passing includeProto: true in config object

const logify = require('method-logger')

class TestClass {
    fn (a) { return a }
    fn2 (a, b) { return a + b }
    fn3 (a, b) { throw new Error('error name') }
};

let proxyLoggerConfig = {
    props: [{
        namePattern: 'fn.*',
    }],
    logger: (target, thisArg, argumentsList) => {console.log(target, argumentsList) },
    includeProto: true
};

let testObj = logify(new TestClass(), proxyLoggerConfig);

testObj.fn(1)           // stdout >> [Function: fn] [ 1 ]
testObj.fn2(1, 2)       // stdout >> [Function: fn2] [ 1, 2 ]
testObj.fn3()           // stdout >> [Function: fn3] []

Different loggers for functions with similar names

In next case for fn$ functions console.trace will be used, for fn(3|2) console.warn will be used, and in other cases default logger - console.log will be used


let config = {
    props: [
        {
            namePattern: 'fn$',
            logger: (target, thisArg, argumentsList) => {console.trace(target, argumentsList) }
        },
        {
            namePattern: 'fn(3|2)',
            logger: (target, thisArg, argumentsList) => {console.warn(target, argumentsList) }
        }
        {
            namePattern: 'customFunction',
        },
        {
            namePattern: '.*',
        },
    ],
    logger: (target, thisArg, argumentsList) => {console.log(target, argumentsList) }
};