@dekor/logger
v0.0.3
Published
a decorator that logs when class method or get property is called
Downloads
12
Readme
@dekor/logger
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