forked from uraymeiviar/burst-pool
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add the following code at the top of the other js files in the directory var poolLogging = require('./burst-pool-logger'); usage is like this poolLogging.writeDateLog('Test') to turn off and on toggle var enabled = false; do not leave on as can cause problems on large pools due to the time it takes to open a large file and write to it
- Loading branch information
SOELexicon
authored and
SOELexicon
committed
Dec 26, 2016
1 parent
0eccddc
commit 1511d15
Showing
2 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
var fs = require('fs'); | ||
|
||
var enabled = false; | ||
var toConsole = false; | ||
var toFile = true; | ||
var toGeneralFile = false; | ||
var generalLogFilename = 'log_general.txt'; | ||
|
||
function TimeStamp() { | ||
var date = new Date(); | ||
var hour = date.getHours(); | ||
hour = (hour < 10 ? "0" : "") + hour; | ||
var min = date.getMinutes(); | ||
min = (min < 10 ? "0" : "") + min; | ||
var sec = date.getSeconds(); | ||
sec = (sec < 10 ? "0" : "") + sec; | ||
var year = date.getFullYear(); | ||
var month = date.getMonth() + 1; | ||
month = (month < 10 ? "0" : "") + month; | ||
var day = date.getDate(); | ||
day = (day < 10 ? "0" : "") + day; | ||
return year + "-" + month + "-" + day + "_" + hour + "-" + min + "-" + sec; | ||
} | ||
function TimeStampFile() { | ||
var date = new Date(); | ||
var hour = date.getHours(); | ||
hour = (hour < 10 ? "0" : "") + hour; | ||
var min = date.getMinutes(); | ||
min = (min < 10 ? "0" : "") + min; | ||
var sec = date.getSeconds(); | ||
sec = (sec < 10 ? "0" : "") + sec; | ||
var year = date.getFullYear(); | ||
var month = date.getMonth() + 1; | ||
month = (month < 10 ? "0" : "") + month; | ||
var day = date.getDate(); | ||
day = (day < 10 ? "0" : "") + day; | ||
return day+ "-" + month + "-" + year; | ||
} | ||
|
||
function write(name,text){ | ||
if (enabled){ | ||
if (toFile){ | ||
fs.appendFile('log_'+name+'.txt', TimeStamp()+' '+text+'\n', function (err) { | ||
if (err) throw err; | ||
}); | ||
} | ||
if (toGeneralFile){ | ||
fs.appendFile(generalLogFilename, TimeStamp()+' ('+name+') '+text+'\n', function (err) { | ||
if (err) throw err; | ||
}); | ||
} | ||
if (toConsole){ | ||
console.log('(logger.'+name+") "+text) | ||
} | ||
} | ||
} | ||
function writeDateLog(text){ | ||
if (enabled){ | ||
|
||
if (toFile){ | ||
fs.exists('./Logs/log_'+TimeStampFile()+'.txt', function(exists) { | ||
if (exists) { | ||
fs.appendFile('./Logs/log_'+TimeStampFile()+'.txt', TimeStamp()+' '+text+'\n', function (err) { | ||
if (err) throw err; | ||
}); | ||
} else { | ||
fs.writeFile('./Logs/log_'+TimeStampFile()+'.txt', TimeStamp()+' '+text+'\n', function(err) { | ||
if(err) { | ||
return console.log(err); | ||
} | ||
|
||
// console.log("The file was saved!"); | ||
}); | ||
} | ||
}); | ||
|
||
} | ||
|
||
} | ||
} | ||
module.exports = { | ||
write : write, | ||
writeDateLog:writeDateLog, | ||
TimeStamp : TimeStamp | ||
}; |