import * as fs from "node:fs"; class Logger { constructor(protocol=null, endpoint, ip) { this.id = ip.split(":")[3]; this.protocol = protocol; this.endpoint = endpoint; this.file = process.env.LOG_FILE; } getCurrentTimestamp() { const time = new Date(); return "[" + time.toISOString().split("T")[0] + " " + time.toISOString().split("T")[1].split("Z")[0] + "]"; } action(action) { const content = fs.readFileSync(this.file).toString(); const payload = this.getCurrentTimestamp() + " [" + this.id + "] " + this.protocol + "(" + this.endpoint + "): " + action + "\n"; console.log(payload); fs.writeFileSync(this.file, content + payload); } write(message, status) { const content = fs.readFileSync(this.file).toString(); const payload = this.getCurrentTimestamp() + " [" + this.id + "] " + this.protocol + "(" + this.endpoint + "): " + message + " with status " + status + "\n"; console.log(payload); fs.writeFileSync(this.file, content + payload); } } export default Logger;