log4js-autolog
A TypeScript method decorator for log4js, just decorate the method to generate a log before/after execution
How to use it
;; ;logger.level = 'debug'; main;
>>>> OUTPUT >>>>[DEBUG] Foo - Foo.greet => 'Hello: Turing'[DEBUG] Foo - async Foo.asyncGreet called[DEBUG] Foo - async Foo.asyncGreet => 'Hello: Turing'[ERROR] Foo - Foo.getLength => TypeError: Cannot read property 'length' of null
Usage
logger
can be aLog4js.Logger
or a string. If it is a string, it is assumed to be a property name of the object, i.e. we callthis[logger]
to get the real logger.opt
is optional and contains the following optional fieldsenterOnly
: if true, log before calling the function, return value (and error) will be ignoredignorePromise
: if true, will NOT track promise resolve/reject (the default value is false and it will track both Promise.resolve and reject)level
: a string, the log level, default is "debug"errLevel
: a string, the log level when exception thrown, default is "warn"timer
if true, will include the total execution time in the log message, only valid for async or promise result