@dekor/logger

0.0.3 • Public • Published

@dekor/logger

npm version npm download monthly npm download total npm dependents npm license pp install size github commit last github commit total

A decorator that logs the method or get property when it is called

Install

$ npm install @dekor/logger

Logger vs LoggerLegacy

For those who use @babel/plugin-proposal-decorators:

  • If the decorated class contains private methods (marked by '#'), use LoggerLegacy, set the plugin: [ '@babel/plugin-proposal-decorators', { legacy: true } ]. because the @babel/plugin-proposal-decorators plugin under 7.10.4 version hasn't supported private fields yet.
  • Otherwise, use Logger, set the plugin: [ '@babel/plugin-proposal-decorators', { legacy: false } ].

Usage - stage 2 mode

import { Logger } from '@dekor/logger'
// if the class contains private field
// import { LoggerLegacy } from '@dekor/logger'

const logger = Logger('decorator:logger')


class Point {
  constructor(x, y) { this.x = x; this.y = y }

  @logger
  get distance() { return Math.sqrt(this.x ** 2 + this.y ** 2) }
}

const p = new Point(3, 4)
p.distance |> console.log

// console outputs:
// > [decorator:logOnCall] 18:29:49.008 calling property Point.distance
// > 10

Meta

LICENSE (MIT)

Package Sidebar

Install

npm i @dekor/logger

Weekly Downloads

2

Version

0.0.3

License

MIT

Unpacked Size

11.9 kB

Total Files

5

Last publish

Collaborators

  • hoyeung