-
-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
33 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// utils/logger.js | ||
|
||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
// Define log file path | ||
const LOG_FILE_PATH = path.join(__dirname, 'app.log'); | ||
|
||
// Logger class | ||
class Logger { | ||
static log(message) { | ||
const timestamp = new Date().toISOString(); | ||
const logMessage = `${timestamp} - INFO: ${message}\n`; | ||
fs.appendFileSync(LOG_FILE_PATH, logMessage); | ||
console.log(logMessage); | ||
} | ||
|
||
static error(message) { | ||
const timestamp = new Date().toISOString(); | ||
const logMessage = `${timestamp} - ERROR: ${message}\n`; | ||
fs.appendFileSync(LOG_FILE_PATH, logMessage); | ||
console.error(logMessage); | ||
} | ||
|
||
static warn(message) { | ||
const timestamp = new Date().toISOString(); | ||
const logMessage = `${timestamp} - WARN: ${message}\n`; | ||
fs.appendFileSync(LOG_FILE_PATH, logMessage); | ||
console.warn(logMessage); | ||
} | ||
} | ||
|
||
module.exports = Logger; |