From 89a7efa95e9813d551e9173ea4bd4764ddda95db Mon Sep 17 00:00:00 2001 From: Ivan Tymoshenko Date: Thu, 4 Apr 2024 17:27:35 +0200 Subject: [PATCH] fix: roll next file only once --- pino-roll.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pino-roll.js b/pino-roll.js index eca81ee..6610236 100644 --- a/pino-roll.js +++ b/pino-roll.js @@ -75,7 +75,7 @@ module.exports = async function ({ let number = await detectLastNumber(file, frequencySpec?.start) - const fileName = buildFileName(file, number, extension) + let fileName = buildFileName(file, number, extension) const createdFileNames = [fileName] let currentSize = await getFileSize(fileName) const maxSize = parseSize(size) @@ -93,7 +93,7 @@ module.exports = async function ({ if (maxSize) { destination.on('write', writtenSize => { currentSize += writtenSize - if (currentSize >= maxSize) { + if (fileName === destination.file && currentSize >= maxSize) { currentSize = 0 // delay to let the destination finish its write setTimeout(roll, 0) @@ -102,7 +102,7 @@ module.exports = async function ({ } function roll () { - const fileName = buildFileName(file, ++number, extension) + fileName = buildFileName(file, ++number, extension) destination.reopen(fileName) if (limit) { createdFileNames.push(fileName)