import LogLevel from './typings/LogLevel'; import Transport from './typings/Transport'; export class Logger { private transports: Transport[]; constructor(transports: Transport[] = []) { this.transports = transports; } attach(transport: Transport) { this.transports.push(transport); } async log(level: LogLevel, module: string, content: string): Promise { const tasks: Promise[] = []; for (const transport of this.transports) { if (!transport.minLevel || level >= transport.minLevel) { tasks.push(transport.log(level, module, content)); } } await Promise.all(tasks); } debug(module: string, content: string) { this.log(LogLevel.Debug, module, content); } info(module: string, content: string) { return this.log(LogLevel.Information, module, content); } warn(module: string, content: string) { return this.log(LogLevel.Warning, module, content); } error(module: string, content: string) { return this.log(LogLevel.Error, module, content); } fatal(module: string, content: string) { return this.log(LogLevel.Fatal, module, content); } } export default Logger;