-
Notifications
You must be signed in to change notification settings - Fork 0
/
log_format.js
53 lines (41 loc) · 1.03 KB
/
log_format.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
function SetZero(num) {
if(num < 10) {
return '0'+num;
} else {
return num;
}
}
function LogStr(str, color) {
let date = new Date();
let date_str = `${SetZero(date.getDate())}/${SetZero(date.getMonth() + 1)}/${SetZero(date.getFullYear())} ${SetZero(date.getHours())}:${SetZero(date.getMinutes())}:${SetZero(date.getSeconds())}`
console.log(`${color} ${date_str} || ${str} `);
}
function LogError(str) {
LogStr('[ERROR] ' + str, '\x1b[31m');
}
function LogWarning(str) {
LogStr('[WARNING] ' +str, '\x1b[33m');
}
function LogOk(str) {
LogStr('[OK] ' +str, '\x1b[32m');
}
function LogInfo(str) {
LogStr('[INFO] ' +str, '\x1b[0m');
}
function Log(type, str) {
switch(type) {
case 'error':
LogError(str);
break;
case 'warning':
LogWarning(str);
break;
case 'ok':
LogOk(str);
break;
default:
LogInfo(str);
break;
}
}
module.exports = Log;