Skip to content

Commit e065a75

Browse files
committed
Fix timeouts for short times
1 parent db8678d commit e065a75

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

lib/fileRotator.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class FileRotator extends EventEmitter {
3737
// Will open existing rather than immediately rotate
3838
await this._initialiseNewFile();
3939
const fileInfo = await fs.stat(this._getFileName(0, false));
40-
this.emit(FileStartTime, fileInfo.birthtime);
40+
this.emit(FileStartTime, fileInfo.birthtimeMs);
4141
}
4242
}
4343

lib/periodTrigger.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ class PeriodTrigger extends EventEmitter {
8080
}
8181

8282
setInitialTime(birthTime) {
83-
this.setNextTask(birthTime + this.period);
83+
this._rotateAt = birthTime;
84+
this.setNextTask();
8485
}
8586

8687
shutdown() {
@@ -89,11 +90,11 @@ class PeriodTrigger extends EventEmitter {
8990
}
9091
}
9192

92-
setNextTask(override) {
93+
setNextTask() {
9394
if (this._task) {
9495
clearTimeout(this._task);
9596
}
96-
this._rotateAt = (typeof override === 'number' ? override : getNextRotation(this._period, this._rotateAt));
97+
this._rotateAt = getNextRotation(this._period, this._rotateAt);
9798
this._task = setTimeout(() => {
9899
this._emitRotate();
99100
this.setNextTask();

test/filerotate.test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,18 @@ describe('RotatingFileStream', function () {
4444
await stream.end();
4545
}, 1000);
4646
});
47+
48+
it('Sets up period correctly', async function () {
49+
const stream = new RotatingFileStream({
50+
period: '1w',
51+
...testConfig
52+
});
53+
bunyan.createLogger({
54+
name: 'foo',
55+
streams: [{
56+
stream
57+
}]
58+
});
59+
await stream.end();
60+
});
4761
});

0 commit comments

Comments
 (0)