-
Notifications
You must be signed in to change notification settings - Fork 0
/
loggerFactory.ts
39 lines (37 loc) · 1.14 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
import { injectable } from 'inversify';
import { ILoggerFactory } from '../interfaces/ILoggerFactory';
import { ConsolaOptions } from 'consola';
import { memoize } from '../../memoize/memoize';
import { ILoggerSettings } from '../interfaces/ILoggerSettings';
import * as chalk from 'chalk';
import { ILogger, LogLevel } from '../interfaces/ILogger';
import { Logger } from './logger';
import { LogReporter } from './logReporter';
@injectable()
export class LoggerFactory extends ILoggerFactory {
private readonly options: ConsolaOptions;
constructor(settings: ILoggerSettings) {
super();
const isDebug = settings.debugMode;
const isTrace = settings.traceMode;
const level = isTrace ? LogLevel.TRACE : isDebug ? LogLevel.DEBUG : LogLevel.INFO;
this.options = {
level,
reporters: [
new LogReporter({
secondaryColor: `grey`,
bgColor: `bgGrey`,
}),
],
};
}
@memoize((category: string): string => category)
public getLogger(category: string): ILogger {
return new Logger({
...this.options,
defaults: {
message: `${chalk.cyan(category)}`,
},
});
}
}