/
loggerFactory.ts
62 lines (56 loc) 路 1.54 KB
/
loggerFactory.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import { ILogger, MidwayAppInfo } from '../interface';
export abstract class LoggerFactory<Logger extends ILogger, LoggerOptions> {
abstract createLogger(name: string, options: LoggerOptions): Logger;
abstract getLogger(loggerName: string): Logger;
abstract close(loggerName?: string);
abstract removeLogger(loggerName: string);
abstract getDefaultMidwayLoggerConfig(appInfo: MidwayAppInfo): {
midwayLogger: {
default?: LoggerOptions;
clients?: {
[loggerName: string]: LoggerOptions;
};
};
};
abstract createContextLogger(
ctx: any,
appLogger: ILogger,
contextOptions?: any
): ILogger;
}
export class DefaultConsoleLoggerFactory
implements LoggerFactory<ILogger, any>
{
private instance: Map<string, ILogger> = new Map();
createLogger(name: string, options: any): ILogger {
this.instance.set(name, console);
return console;
}
getLogger(loggerName: string): ILogger {
return this.instance.get(loggerName);
}
close(loggerName?: string) {}
removeLogger(loggerName: string) {}
getDefaultMidwayLoggerConfig(): {
midwayLogger: { default?: any; clients?: { [p: string]: any } };
} {
return {
midwayLogger: {
default: {},
clients: {
coreLogger: {},
appLogger: {},
},
},
};
}
createContextLogger(ctx: any, appLogger: ILogger, contextOptions?): ILogger {
return appLogger;
}
public getClients() {
return this.instance;
}
public getClientKeys() {
return Array.from(this.instance.keys());
}
}