-
Notifications
You must be signed in to change notification settings - Fork 0
/
logger.js
67 lines (67 loc) · 1.46 KB
/
logger.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/**
* Logs a message with the specified type.
* @param {string} message - The message to be logged.
* @param {number} [type=0] - The type of the log. 0 for info, 1 for warn, 2 for error.
*/
let config = require("./config.json");
const log = (message, type = 0) => {
let logType;
switch (type) {
case 0:
logType = "\x1b[37m[INFO]\x1b[0m"; // White
break;
case 1:
logType = "\x1b[33m[WARN]\x1b[0m"; // Yellow
break;
case 2:
logType = "\x1b[31m[ERROR]\x1b[0m"; // Red
break;
default:
logType = "\x1b[37m[INFO]\x1b[0m"; // White
break;
}
let date = new Date();
console.log(
logType,
date.getDate() +
"/" +
(date.getMonth() + 1) +
"/" +
date.getFullYear() +
" @ " +
date.getHours() +
":" +
date.getMinutes() +
":" +
date.getSeconds(),
message
);
if (config.saveLog) {
let fs = require("fs");
fs.appendFile(
`./logs/${
date.getDate() + "." + (date.getMonth() + 1) + "." + date.getFullYear()
}.txt`,
logType +
" " +
date.getDate() +
"/" +
(date.getMonth() + 1) +
"/" +
date.getFullYear() +
" @ " +
date.getHours() +
":" +
date.getMinutes() +
":" +
date.getSeconds() +
" " +
message +
"\n",
function (err) {
if (err) throw err;
}
);
}
};
module.exports = { log };