Added debug logging

This commit is contained in:
MrFry 2020-03-12 22:25:26 +01:00
parent 72aefca297
commit a7a75bd9d4
4 changed files with 62 additions and 6 deletions

View file

@ -18,14 +18,18 @@
------------------------------------------------------------------------- */
const hr = '---------------------------------------------------------------------------------'
module.exports = {
GetDateString: GetDateString,
Log: Log,
DebugLog: DebugLog,
GetColor: GetColor,
LogReq: LogReq,
LogStat: LogStat,
Load: Load,
logHashed: logHashed
logHashed: logHashed,
hr: hr
}
const DELIM = C('green') + '|' + C()
@ -43,6 +47,7 @@ const writeInterval = 10
let data = {}
let vData = {}
let writes = 0
let debugLevel = 0
const colors = [
'green',
@ -66,9 +71,25 @@ function GetDateString () {
return GetRandomColor(m.getHours().toString()) + d + C()
}
function DebugLog (msg, lvl) {
if (lvl <= debugLevel) {
let s = msg
let header = C('red') + '#DEBUG ' + lvl + '#' + C() + DELIM + C()
if (typeof msg !== 'object') {
s = header + msg
} else {
Log(header + 'OBJECT:', 'yellow')
}
Log(s, 'yellow')
}
}
function Log (s, c) {
let dl = DELIM + C(c)
let log = C(c) + GetDateString() + dl + s
let log = s
if (typeof s !== 'object') {
let dl = DELIM + C(c)
log = C(c) + GetDateString() + dl + s
}
console.log(log)
utils.AppendToFile(log, logFile)
@ -132,7 +153,10 @@ function setNoLogReadInterval () {
parseNoLogFile(utils.ReadFile(nologFile))
}
function Load () {
function Load (debugLvl) {
if (debugLvl) {
debugLevel = debugLvl
}
Log('Loading logger...')
try {
var prevData = utils.ReadFile(statFile)