add typescript to backend

This commit is contained in:
fred 2025-08-15 15:02:11 -07:00
parent 0a41568a2e
commit 30b28056de
10 changed files with 221 additions and 67 deletions

View file

@ -0,0 +1,35 @@
import fs from "fs";
class Logger {
private filePath: string;
constructor(filePath: string = "/logs/app.log") {
this.filePath = filePath;
}
private log(level: string, message: string, params?: object) {
const logEntry = {
timestamp: new Date().toISOString(),
level: level,
message: message,
params: params,
};
fs.appendFile(this.filePath, JSON.stringify(logEntry) + "\n", (err) => {
if (err) throw err;
});
}
info(message: string, params: object = {}) {
this.log("info", message, params);
}
warn(message: string, params: object = {}) {
this.log("warn", message, params);
}
error(message: string, params: object = {}) {
this.log("error", message, params);
}
}
export default Logger;