Git Product home page Git Product 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

ajv icon ajv

The fastest JSON Schema Validator. Supports draft-04/06/07

alexa icon alexa

Monorepo of libraries used for Amazon Alexa development

astcenc icon astcenc

A command-line tool for compressing and decompressing images using the ASTC texture compression standard.

async-with-timeout icon async-with-timeout

A node utility function that implements timeout and AbortSignal support for async functions.

berry icon berry

πŸ“¦πŸˆ Active development trunk for Yarn βš’

concrete icon concrete

Functions to help with absolute positioning

debug-logger icon debug-logger

A TypeScript decorator for classes that logs all method usages

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.