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:
parent
7bf2e4de76
commit
adef37c8ad
3 changed files with 29 additions and 6 deletions
|
@ -1 +1 @@
|
||||||
Subproject commit cbfaffa70ceb29b4beac4b13f6cbb4b85baac8a8
|
Subproject commit fe74436ab119a31fdb35f7a3bbae50a572b0fb21
|
|
@ -113,10 +113,13 @@ function LogReq (req, toFile, sc) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function setNoLogReadInterval () {
|
function setNoLogReadInterval () {
|
||||||
noLogips = utils.ReadFile('./nolog').split('\n')
|
utils.WatchFile('./nolog', (newData) => {
|
||||||
setInterval(() => {
|
noLogips = newData.split('\n')
|
||||||
noLogips = utils.ReadFile('./nolog').split('\n')
|
if (noLogips[noLogips.length - 1] === '') {
|
||||||
}, 1000 * 60 * 30)
|
noLogips.pop()
|
||||||
|
}
|
||||||
|
Log('\tNo Log IP-s changed: ' + noLogips.join(', '))
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function Load () {
|
function Load () {
|
||||||
|
|
|
@ -6,7 +6,8 @@ module.exports = {
|
||||||
Beep: Beep,
|
Beep: Beep,
|
||||||
WriteBackup: WriteBackup,
|
WriteBackup: WriteBackup,
|
||||||
FileExists: FileExists,
|
FileExists: FileExists,
|
||||||
CreatePath: CreatePath
|
CreatePath: CreatePath,
|
||||||
|
WatchFile: WatchFile
|
||||||
}
|
}
|
||||||
|
|
||||||
var fs = require('fs')
|
var fs = require('fs')
|
||||||
|
@ -24,6 +25,25 @@ function FileExists (path) {
|
||||||
return fs.existsSync(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) {
|
function CreatePath (path, onlyPath) {
|
||||||
if (FileExists(path)) { return }
|
if (FileExists(path)) { return }
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue