Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: roll next file only once #74

Merged
merged 1 commit into from
Apr 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions pino-roll.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down