add typescript to backend
This commit is contained in:
parent
0a41568a2e
commit
30b28056de
10 changed files with 221 additions and 67 deletions
35
backend/src/utils/logger.ts
Normal file
35
backend/src/utils/logger.ts
Normal 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;
|
||||
Loading…
Add table
Add a link
Reference in a new issue