Fix log parser with multiple files

This commit is contained in:
Chocobozzz 2022-07-12 16:21:13 +02:00
parent f686f5ed0a
commit 5220859984
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
1 changed files with 34 additions and 30 deletions

View File

@ -76,13 +76,17 @@ run()
.then(() => process.exit(0))
.catch(err => console.error(err))
function run () {
return new Promise<void>(async res => {
async function run () {
const files = await getFiles()
for (const file of files) {
if (file === 'peertube-audit.log') continue
await readFile(file)
}
}
function readFile (file: string) {
console.log('Opening %s.', file)
const stream = createReadStream(file)
@ -91,6 +95,7 @@ function run () {
input: stream
})
return new Promise<void>(res => {
rl.on('line', line => {
try {
const log = JSON.parse(line)
@ -113,7 +118,6 @@ function run () {
})
stream.once('close', () => res())
}
})
}