Skip to content

Commit

Permalink
Create logger.js
Browse files Browse the repository at this point in the history
  • Loading branch information
KOSASIH authored Dec 4, 2024
1 parent 00dfdbf commit 20c49b3
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/utils/logger.js
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;

0 comments on commit 20c49b3

Please sign in to comment.