bunyan-rotating-file-stream icon indicating copy to clipboard operation
bunyan-rotating-file-stream copied to clipboard

Rotate existing not rotating at correct interval

Open Zacharias3690 opened this issue 6 years ago • 1 comments

When a file is less than 24 hours old (daily), initialPeriodCheck fails to trigger new file creation. Next Rotation time checks 24 hours since birthtime instead of at midnight of the day after birthtime, causing no new file to be created at startup.

Relevant code:

//  initialperiodtrigger.js
function checkIfRotationNeeded(birthtime, now) {
    var nextRot = birthtime;
    var lastRot = birthtime;
    while (nextRot < now) {
        lastRot = nextRot;
        nextRot = nextRotTime(lastRot, periodScope, periodNum);
    }

    return { needsRotation: lastRot != birthtime, rotateTo: lastRot };
}
// nextrotationtime.js
case 'd':
    if (rotAt) {
        newRotAt = rotAt + periodNum * 24 * 60 * 60 * 1000;
    } else {
        // First time: start of tomorrow (i.e. at the coming midnight) UTC.
        newRotAt = Date.UTC(d.getUTCFullYear(), d.getUTCMonth(),
            d.getUTCDate() + 1);
    }
    break;  

e.g. if file is created at 11:30am Mar 28, rotAt is passed in as 11:30am Mar 28, and newRotAt returns 11:30am Mar 29, so if the time is after Midnight on Mar 29, but before 11:30am, no new file is created.

From looking at the code it looks like this issue will be with hourly and weekly as well.

Zacharias3690 avatar Mar 28 '18 18:03 Zacharias3690

Facing the same issue for ms as well... do we have any update on this?

gopal-abbineni avatar Sep 25 '20 13:09 gopal-abbineni