-
Notifications
You must be signed in to change notification settings - Fork 3
/
utils.js
68 lines (55 loc) · 2.08 KB
/
utils.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
68
debugmode = false
var fs = require('fs');
const config = require("./config");
var date = new Date();
logName = "./logs/" + date.getDate() + "." + date.getMonth() + "." + date.getFullYear() + "_" + date.getHours() + "_" + date.getMinutes() + "_" + date.getSeconds() + ".log"
function log(type, msg) {
if (config.developerOptions.saveLogFiles == "true") {
var date = new Date();
msg = "[" + type + " @ " + date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds() + "]: " + msg
fs.appendFile(logName, msg + "\n", function(err) {
if(err) {
exports.warningMessage(err);
}
});
}
}
exports.debugMode = function () {
debugmode = true;
}
exports.toBase64 = function (str) {
return Buffer.from(str).toString("base64");
};
exports.fromBase64 = function (b64) {
return Buffer.from(b64, "base64").toString("utf8")
};
exports.infoMessage = function (str, force) {
if (config.developerOptions.logOtherMessages == "true" || force == "force" || force == true || debugmode == true) {
console.log('\x1b[2m\x1b[36m%s\x1b[0m', "[-] ".concat(str));
}
log("INFO", str)
};
exports.successMessage = function (str, force) {
if (config.developerOptions.logOtherMessages == "true" || force == "force" || force == true || debugmode == true) {
console.log('\x1b[2m\x1b[32m%s\x1b[0m', "[*] ".concat(str));
}
log("SUCCESS", str)
}
exports.warningMessage = function (str, force) {
if (config.developerOptions.logOtherMessages == "true" || force == "force" || force == true || debugmode == true) {
console.log('\x1b[2m\x1b[35m%s\x1b[0m', "[!] ".concat(str));
}
log("WARN", str)
}
exports.errorMessage = function (str, force) {
if (config.developerOptions.logOtherMessages == "true" || force == "force" || force == true || debugmode == true) {
console.error('\x1b[2m\x1b[31m%s\x1b[0m', "[!] ".concat(str));
}
log("ERR", str)
}
exports.debugMessage = function (str, force) {
if (config.developerOptions.logDebugMessages == "true" || force == "force" || force == true || debugmode == true) {
console.log('\x1b[2m\x1b[33m%s\x1b[0m', "[#] ".concat(str));
}
log("DEBUG", str)
}