-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathLoggingDecorator.ts
More file actions
27 lines (22 loc) · 741 Bytes
/
LoggingDecorator.ts
File metadata and controls
27 lines (22 loc) · 741 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/** biome-ignore-all lint/suspicious/noExplicitAny: it is dynamic by definition */
import { Logger, lazy } from './LoggingService.js'
export function log(
target: any,
propertyKey: string,
descriptor: PropertyDescriptor
): void {
const original = descriptor.value
descriptor.value = function (...args: any[]) {
Logger.trace(lazy`${target.constructor.name}.${propertyKey}: entry`)
const call = () => original.call(this, ...args)
const logResult = (result: any) => {
Logger.trace(lazy`${target.constructor.name}.${propertyKey}: exit`)
return result
}
if (original.constructor.name === 'AsyncFunction') {
return call().then(logResult)
} else {
return logResult(call())
}
}
}