-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogger_text.ts
More file actions
75 lines (71 loc) · 2.19 KB
/
logger_text.ts
File metadata and controls
75 lines (71 loc) · 2.19 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import path from 'node:path';
import url from 'node:url';
import b from 'benny';
import { BenchHandler, suiteCommon } from './utils/index.js';
import Logger, { LogLevel, formatting } from '#index.js';
const filePath = url.fileURLToPath(import.meta.url);
async function main() {
const msg = 'Hello World';
const data = { foo: 'bar', bar: () => 'foo' };
const summary = await b.suite(
path.basename(filePath, path.extname(filePath)),
b.add('formatting default', () => {
const logger = new Logger('root', LogLevel.NOTSET, [
new BenchHandler(formatting.formatter),
]);
return () => {
logger.info(msg, data);
};
}),
b.add('formatting with keys path', () => {
const logger = new Logger('root', LogLevel.NOTSET, [
new BenchHandler(
formatting.format`${formatting.level}:${formatting.keys}:${formatting.msg}`,
),
]);
const loggerChild = logger.getChild('child');
return () => {
loggerChild.info(msg, data);
};
}),
b.add('formatting with date', () => {
const logger = new Logger('root', LogLevel.NOTSET, [
new BenchHandler(
formatting.format`${formatting.level}:${formatting.keys}:${formatting.msg}:${formatting.date}`,
),
]);
return () => {
logger.info(msg, data);
};
}),
b.add('formatting with data', () => {
const logger = new Logger('root', LogLevel.NOTSET, [
new BenchHandler(
formatting.format`${formatting.level}:${formatting.keys}:${formatting.msg}:${formatting.data}`,
),
]);
return () => {
logger.info(msg, data);
};
}),
b.add('formatting with stacktrace', () => {
const logger = new Logger('root', LogLevel.NOTSET, [
new BenchHandler(
formatting.format`${formatting.level}:${formatting.key}:${formatting.msg}${formatting.stack}`,
),
]);
return () => {
logger.info(msg, data);
};
}),
...suiteCommon,
);
return summary;
}
if (import.meta.url.startsWith('file:')) {
const modulePath = url.fileURLToPath(import.meta.url);
if (process.argv[1] === modulePath) {
void main();
}
}
export default main;