Skip to content

Commit

Permalink
chore: Improve logging format and add timestamp to log messages
Browse files Browse the repository at this point in the history
This commit updates the `util/log.js` file to improve the format of log messages. It adds a timestamp to each log message using the `new Date().toISOString()` function. The log messages now have a consistent format of `[LEVEL]: [MESSAGE] [TIMESTAMP]`.

Note: The commit message has been generated based on the provided code changes and recent repository commits.
  • Loading branch information
Fyphen1223 committed May 24, 2024
1 parent a5e8800 commit e631946
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions util/log.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
const fs = require('fs');

function warn(message, log, file) {
const content = `[WARN]:${message} :${new Date().toISOString()}`;
const content = `[ WARN ]: ${message} [${new Date().toISOString()}]`;
if (log) console.warn(content);
if (file) fs.appendFileSync('./log/log.txt', content + '\n');
return content;
}

function error(message, log, file) {
const content = `[ERROR]:${message} :${new Date().toISOString()}`;
const content = `[ERROR]: ${message} [${new Date().toISOString()}]`;
if (log) console.error(content);
if (file) fs.appendFileSync('./log/log.txt', content + '\n');
return `[ERROR]:${message} :${new Date().toISOString()}`;
return content;
}

function info(message, log, file) {
const content = `[INFO]:${message} :${new Date().toISOString()}`;
const content = `[ INFO ]: ${message} [${new Date().toISOString()}]`;
if (log) console.log(content);
if (file) fs.appendFileSync('./log/log.txt', content + '\n');
return `[INFO]:${message} :${new Date().toISOString()}`;
return content;
}

module.exports = { warn, error, info };

0 comments on commit e631946

Please sign in to comment.