1 |
import DiscordClient from "../client/Client"; |
2 |
import { Guild } from "discord.js"; |
3 |
import { appendFile } from "fs/promises"; |
4 |
|
5 |
export enum LogLevel { |
6 |
LOG = 'log', |
7 |
INFO = 'info', |
8 |
WARN = 'warn', |
9 |
CRITICAL = 'critical', |
10 |
ERROR = 'error' |
11 |
} |
12 |
|
13 |
export default class DebugLogger { |
14 |
private joinLeaveLogFile = __dirname + '/../../logs/join-leave.log'; |
15 |
private appLogFile = __dirname + '/../../logs/app.log'; |
16 |
|
17 |
constructor(protected client: DiscordClient) { |
18 |
|
19 |
} |
20 |
|
21 |
async logApp(level: LogLevel, message: string) { |
22 |
await this.log(this.appLogFile, level, message); |
23 |
} |
24 |
|
25 |
async logLeaveJoin(level: LogLevel, message: string) { |
26 |
await this.log(this.joinLeaveLogFile, level, message); |
27 |
} |
28 |
|
29 |
async log(stream: string, level: LogLevel, message: string) { |
30 |
await appendFile(stream, `[${new Date().toISOString()}] [${level}] ${message}\n`); |
31 |
} |
32 |
} |