Fix log parser with multiple files

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