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 🙏

© 2024 – Pkg Stats / Ryan Hefner

proxy-logger

v1.1.3

Published

A logging utility which wraps utility classes in a proxy function. Enables automated logging of any function calls! All logs are written and parsed into markdown to make it easy and clean to debug.

Downloads

16

Readme

Proxy-Logger

A proxy based logger for utility classes in node.js!

Features

  • Automatically log all preconditions, postconditions, and changes to class state by wrapping the class in a Proxy Logger.
  • All logs are written to markdown so they are clean to review, just right click and Markdown Preview in Atom.
  • No more filling functions with more logs than functional code, classes are automatically logged!

Installing

Using npm:

$ npm install proxy-logger

Using yarn:

$ yarn add proxy-logger

Example

Instantiating the Proxy Logger

App.js

const ProxyLogger = require('proxy-logger');

const copywrite = `Copyright 2019 Durban-Designer : Royce Birnbaum

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in the
Software without restriction, including without limitation the rights to use, copy,
modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to do so, subject to the
following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
USE OR OTHER DEALINGS IN THE SOFTWARE.`;

const name = `Proxy Logger`;

const location = './logs';

const testLog = {
  class: 'test',
  message: 'testLog is added manually by the addLog test',
  data: [
    {
      object: 'test',
      test: []
    }
  ]
};

const test = require('./TestClass.js');

ProxyLogger.init(copywrite, name, location);

test.testA();
test.testB();

ProxyLogger.addLog(testLog);

process.exit();
  • note if you don't specify copywrite it will be as above

  • note if you don't specify name it will be as above

  • note if you don't specify location it will default to ./logs

  • WARNING if you don't call ProxyLogger.init() the exit listener wont trigger and logs wont write!

Wrapping a utility class

TestClass.js
const ProxyLogger = require('proxy-logger');

class TestClass {
  constructor () {
    this.a = null;
    this.b = null;
  }

  testA () {
    this.a = 1;
  }

  testB () {
    this.b = 2;
  }
}

module.exports = ProxyLogger.wrap(new TestClass());

Writing the log

  • logs are automatically written when the application closes.

Manually adding a log

const ProxyLogger = require('proxy-logger');

ProxyLogger.addLog({
  class: 'class name',
  message: 'a string with a message to log',
  data: {
    key1: value1,
    key2: value2,
    keyn: valuen
  }
})
  • Class can be any string
  • Message can be any string
  • data can be any JSON object or Array

Testing

$ npm install --dev

$ npm install -g mocha

$ npm test

Resources

Credits

  • Soorena
    • inspired by your stack overflow post on proxying class methods
  • FarzaTv
    • at 5am your post with a King Theta song got me in the zone to code this passion project.
    • Check out Kanga GG for some cool ML + league
  • Grapetoast
    • Thanks for pushing me to improve logging beyond a manual implimentation.

License

MIT

Example Log

Copyright 2019 Durban-Designer : Royce Birnbaum

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Begin logs at time Jun-16th-2019 10:45:13

TestClass - 0.019s runtime
Calling Method: testA,
Target class: TestClass
TestClass - 0.02s runtime
Pre Condition
Data:
{
    "a": null,
    "b": null
}
TestClass - 0.02s runtime
Begin set state operation
TestClass - 0.02s runtime
Key to update: a,
Old Value: null,
New Value: 1
TestClass - 0.02s runtime
Post Condition
Data:
{
    "a": 1,
    "b": null
}
TestClass - 0.02s runtime
Calling Method: testB,
Target class: TestClass
TestClass - 0.02s runtime
Pre Condition
Data:
{
    "a": 1,
    "b": null
}
TestClass - 0.02s runtime
Begin set state operation
TestClass - 0.021s runtime
Key to update: b,
Old Value: null,
New Value: 2
TestClass - 0.021s runtime
Post Condition
Data:
{
    "a": 1,
    "b": 2
}
test - 0.026s runtime
testLog is added manually by the addLog test
Data:
{
    "object": "test",
    "test": []
}
test - 0.028s runtime
testLog is added manually by the addLog test
Data:
{
    "object": "test",
    "test": []
}

Total Runtime 0.031 seconds