forked from CryptoGnome/Bybit-Lick-Hunter-v4
-
Notifications
You must be signed in to change notification settings - Fork 0
/
log.js
34 lines (28 loc) · 921 Bytes
/
log.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
import { env } from 'process';
import moment from 'moment';
import fs from 'fs';
export const LOG_LEVEL = {
UNDEFINED : -1,
DEBUG : 0,
INFO : 1,
WARNING : 2,
ERROR : 3,
};
const logLevelStr = ["DEBUG", "INFO", "WARNING", "ERROR"];
export function logIT(msg, level = LOG_LEVEL.INFO) {
const logLevel = logLevelStr.findIndex(el => el == process.env.LOG_LEVEL);
if (logLevel == -1)
console.log('[' + moment().local().toString() + '] :: ' + "ERROR BAD LOG LEVEL")
if (level < logLevel)
return;
console.log('[' + moment().local().toString() + '] :: ' + msg)
// Log to file
if (process.env.USE_LOG == "true"){
fs.appendFile('log', '[' + moment().local().toString() + '] ' + msg.replace(/\u001b\[\d+m/g, '') + '\n', function (err) {
if (err) {
logIT("Logging error: " + err);
return console.log("Logging error: " + err);
}
});
}
}