mirror of
https://gitlab.com/MrFry/mrfrys-node-server
synced 2025-04-01 20:24:18 +02:00
NoLog file watching
This commit is contained in:
@@ -113,10 +113,13 @@ function LogReq (req, toFile, sc) {
|
||||
}
|
||||
|
||||
function setNoLogReadInterval () {
|
||||
noLogips = utils.ReadFile('./nolog').split('\n')
|
||||
setInterval(() => {
|
||||
noLogips = utils.ReadFile('./nolog').split('\n')
|
||||
}, 1000 * 60 * 30)
|
||||
utils.WatchFile('./nolog', (newData) => {
|
||||
noLogips = newData.split('\n')
|
||||
if (noLogips[noLogips.length - 1] === '') {
|
||||
noLogips.pop()
|
||||
}
|
||||
Log('\tNo Log IP-s changed: ' + noLogips.join(', '))
|
||||
})
|
||||
}
|
||||
|
||||
function Load () {
|
||||
|
@@ -6,7 +6,8 @@ module.exports = {
|
||||
Beep: Beep,
|
||||
WriteBackup: WriteBackup,
|
||||
FileExists: FileExists,
|
||||
CreatePath: CreatePath
|
||||
CreatePath: CreatePath,
|
||||
WatchFile: WatchFile
|
||||
}
|
||||
|
||||
var fs = require('fs')
|
||||
@@ -24,6 +25,25 @@ function FileExists (path) {
|
||||
return fs.existsSync(path)
|
||||
}
|
||||
|
||||
function WatchFile (file, callback) {
|
||||
if (FileExists(file)) {
|
||||
fs.watchFile(file, (curr, prev) => {
|
||||
fs.readFile(file, 'utf8', (err, data) => {
|
||||
if (err) {
|
||||
// console.log(err)
|
||||
} else {
|
||||
callback(data)
|
||||
}
|
||||
})
|
||||
})
|
||||
} else {
|
||||
console.log(file + ' does not eadjsalék')
|
||||
setTimeout(() => {
|
||||
WatchFile(file)
|
||||
}, 1000)
|
||||
}
|
||||
}
|
||||
|
||||
function CreatePath (path, onlyPath) {
|
||||
if (FileExists(path)) { return }
|
||||
|
||||
|
Reference in New Issue
Block a user