blob: 11a24f79b8381ba8ed892572718c418cbfe4ebf5 (
plain)
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
|
export interface TracingLogger {
info(log: string): void;
warn(log: string): void;
error(log: string): void;
createChild(prefix: string): TracingLogger;
}
export class ConsoleTracingLogger implements TracingLogger {
protected prefix: string;
constructor(prefix: string) {
this.prefix = prefix;
}
private makePrefix(level: 'info' | 'warn' | 'error'): string {
return `[${new Date().toISOString()}] ${level} (${this.prefix}) > `;
}
public info(log: string) {
console.log(this.makePrefix('info') + log);
}
public warn(log: string) {
console.warn(this.makePrefix('warn') + log);
}
public error(log: string) {
console.error(this.makePrefix('error') + log);
}
public createChild(prefix: string) {
return new ConsoleTracingLogger(`${this.prefix} -> ${prefix}`);
}
}
|