(init): Add initial logger files.
This commit is contained in:
44
src/Logger.ts
Normal file
44
src/Logger.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
import LogLevel from './typings/LogLevel';
|
||||
import Transport from './typings/Transport';
|
||||
|
||||
export class Logger {
|
||||
private transports: Transport[];
|
||||
|
||||
constructor(transports: Transport[] = []) {
|
||||
this.transports = transports;
|
||||
}
|
||||
|
||||
async log(level: LogLevel, module: string, content: string): Promise<void> {
|
||||
const tasks: Promise<void>[] = [];
|
||||
|
||||
for (const transport of this.transports) {
|
||||
if (level >= transport.minLevel) {
|
||||
tasks.push(transport.log(level, module, content));
|
||||
}
|
||||
}
|
||||
|
||||
await Promise.all(tasks);
|
||||
}
|
||||
|
||||
debug(module: string, content: string) {
|
||||
return 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;
|
||||
Reference in New Issue
Block a user