generated from MatrixAI/TypeScript-Demo-Lib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.ts
42 lines (37 loc) · 919 Bytes
/
utils.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
import type { LogData } from './types.js';
import { LogLevel } from './types.js';
const hasCaptureStackTrace = 'captureStackTrace' in Error;
const hasStackTraceLimit = 'stackTraceLimit' in Error;
function levelToString(level: LogLevel): string {
switch (level) {
case LogLevel.NOTSET:
return 'NOTSET';
case LogLevel.DEBUG:
return 'DEBUG';
case LogLevel.INFO:
return 'INFO';
case LogLevel.WARN:
return 'WARN';
case LogLevel.ERROR:
return 'ERROR';
case LogLevel.SILENT:
return 'SILENT';
}
}
function evalLogDataValue(this: any, _key: string, value: any): any {
if (typeof value === 'function') {
return value();
} else {
return value;
}
}
function evalLogData(data: LogData) {
return JSON.stringify(data, evalLogDataValue);
}
export {
levelToString,
evalLogDataValue,
evalLogData,
hasCaptureStackTrace,
hasStackTraceLimit,
};