recipe_app/backend/src/utils/logger.ts

36 lines
773 B
TypeScript
Raw Normal View History

2025-08-15 15:02:11 -07:00
import fs from "fs";
class Logger {
2025-08-15 15:02:11 -07:00
private filePath: string;
constructor(filePath: string = "/logs/app.log") {
this.filePath = filePath;
}
2025-08-15 15:02:11 -07:00
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;
});
}
2025-08-15 15:02:11 -07:00
info(message: string, params: object = {}) {
this.log("info", message, params);
}
2025-08-15 15:02:11 -07:00
warn(message: string, params: object = {}) {
this.log("warn", message, params);
}
2025-08-15 15:02:11 -07:00
error(message: string, params: object = {}) {
this.log("error", message, params);
}
}
2025-08-15 15:02:11 -07:00
export default Logger;