Giter Club home page Giter Club 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

pki.js icon pki.js

PKI.js is a pure JavaScript library implementing the formats that are used in PKI applications (signing, encryption, certificate requests, OCSP and TSP requests/responses). It is built on WebCrypto (Web Cryptography API) and requires no plug-ins.

playwright icon playwright

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

regulation icon regulation

A monorepo of libraries and tools for parsing and converting Regulation lang to regular expressions

resolve-bin icon resolve-bin

Resolves the full path to the bin file of a given package by inspecting the \"bin\" field in its package.json.

shift icon shift

A few jscodeshift transforms

solidarity icon solidarity

Solidarity is an environment checker for project dependencies across multiple machines.

sort-order icon sort-order

Combine a series of sort functions to create complex sort orders.

table icon table

A tagged template for defining a table of data.

type-extractor icon type-extractor

Extract types that are embedded in a package to a separate @types package

typescript-eslint icon typescript-eslint

:sparkles: Monorepo for all the tooling which enables ESLint to support TypeScript

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.