Giter Site home page Giter Site logo

@cameronhunter/debug-logger

A TypeScript decorator for classes that logs all method usages using the debug package. Logging is enabled using the DEBUG environment variable – see the debug package for details.

Examples

Simple usage

The decorator can be used directly and it will log to a namespace matching the class name it is decorating. An execution of new HelloWorld().main('World') below will result in HelloWorld main("World"); being logged.

import DebugLogging from '@cameronhunter/debug-logger';

@DebugLogging
class HelloWorld {
  main(name: string) {
    console.log(`Hello ${name}!`);
  }
}

Using a custom namespace

The decorator also accepts an optional namespace that will be used in addition to the class name it is decorating. An execution of new HelloWorld().main('World') below will result in my-debug-namespace:HelloWorld main("World"); being logged.

import DebugLogging from '@cameronhunter/debug-logger';

@DebugLogging('my-debug-namespace')
class HelloWorld {
  main(name: string) {
    console.log(`Hello ${name}!`);
  }
}

Configuring a shared logger

The decorator can be preconfigured and shared. For example, we can configure a debug logger with a custom namespace and export it for use around an application. An execution of new HelloWorld().main('World') below will result in my-namespace:HelloWorld main("World"); being logged.

import DebugLogger from '@cameronhunter/debug-logger';

const CustomLogger = DebugLogger('my-namespace');

@CustomLogger
class HelloWorld {
  main(name: string) {
    console.log(`Hello ${name}!`);
  }
}

Cameron Hunter's Projects

glacier-cli icon glacier-cli

Amazon AWS Glacier command line interface for Linux, Mac and Windows

happydays icon happydays

Android application that notifies you of your contacts' birthdays and anniversaries.

ink icon ink

🌈 React for interactive command-line apps

jest icon jest

πŸƒ Delightful JavaScript Testing.

jest-codemods icon jest-codemods

Codemods for migrating to Jest https://github.com/facebook/jest πŸ‘Ύ

jest-each-table icon jest-each-table

Create a test-case table for use with Jest's test.each tagged template literal

jimp icon jimp

An image processing library written entirely in JavaScript for Node, with zero external or native dependencies.

jquery-plugin-factory icon jquery-plugin-factory

A plugin which takes care of all the jQuery plugin best practices for you, so you can focus on the functionality

jsonpath icon jsonpath

Query and manipulate JavaScript objects with JSONPath expressions. Robust JSONPath engine for Node.js.

just icon just

A library of dependency-free utilities that do just do one thing.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.