-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLoggableMixin.ts
48 lines (44 loc) · 1.19 KB
/
LoggableMixin.ts
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import type {
ILogObject,
ILoggableMixin,
} from '../interfaces/index'
/**
* @utyfua:
* - I understand `.debug` exists for causes like this
* but in my practice I should collect such information
* and save in logs witch I can easily filter it after.
*/
export function applyLoggableMixin(base: any): any {
class LoggableMixin extends base implements ILoggableMixin {
recordError(
message: ILogObject["message"],
error?: ILogObject["error"],
...meta: ILogObject["meta"]
) {
this.logger({
level: 'error',
message,
error,
meta,
})
}
recordInternalError(
message: ILogObject["message"],
...meta: ILogObject["meta"]
) {
const error = new Error(message);
this.recordError(message, error, ...meta)
}
recordWarning(
message: ILogObject["message"],
...meta: ILogObject["meta"]
) {
this.logger({
level: 'warning',
message,
meta,
})
}
}
return LoggableMixin
}