|
1
|
import { Logger } from "@medusajs/framework/types" |
|
2
|
|
|
3
|
/** |
|
4
|
* In-memory logger that records every log entry. Errors are collected |
|
5
|
* separately so the test bed can fail loudly when the module swallows |
|
6
|
* exceptions and only reports them through the logger. |
|
7
|
*/ |
|
8
|
export class FakeLogger { |
|
9
|
logs: { level: string; args: unknown[] }[] = [] |
|
10
|
errors: unknown[] = [] |
|
11
|
|
|
12
|
protected record(level: string, args: unknown[]) { |
|
13
|
this.logs.push({ level, args }) |
|
14
|
|
|
15
|
if (level === "error") { |
|
16
|
this.errors.push(args[0]) |
|
17
|
} |
|
18
|
} |
|
19
|
|
|
20
|
info(...args: unknown[]) { |
|
21
|
this.record("info", args) |
|
22
|
} |
|
23
|
|
|
24
|
warn(...args: unknown[]) { |
|
25
|
this.record("warn", args) |
|
26
|
} |
|
27
|
|
|
28
|
error(...args: unknown[]) { |
|
29
|
this.record("error", args) |
|
30
|
} |
|
31
|
|
|
32
|
debug(...args: unknown[]) { |
|
33
|
this.record("debug", args) |
|
34
|
} |
|
35
|
|
|
36
|
log(...args: unknown[]) { |
|
37
|
this.record("log", args) |
|
38
|
} |
|
39
|
|
|
40
|
panic(...args: unknown[]) { |
|
41
|
this.record("panic", args) |
|
42
|
} |
|
43
|
|
|
44
|
failure(...args: unknown[]) { |
|
45
|
this.record("failure", args) |
|
46
|
} |
|
47
|
|
|
48
|
success(...args: unknown[]) { |
|
49
|
this.record("success", args) |
|
50
|
} |
|
51
|
|
|
52
|
progress(...args: unknown[]) { |
|
53
|
this.record("progress", args) |
|
54
|
} |
|
55
|
|
|
56
|
activity(...args: unknown[]) { |
|
57
|
this.record("activity", args) |
|
58
|
} |
|
59
|
|
|
60
|
shouldLog(): boolean { |
|
61
|
return true |
|
62
|
} |
|
63
|
|
|
64
|
setLogLevel(): void {} |
|
65
|
|
|
66
|
unsetLogLevel(): void {} |
|
67
|
|
|
68
|
asLogger(): Logger { |
|
69
|
return this as unknown as Logger |
|
70
|
} |
|
71
|
} |