Skip to content

Commit d67d067

Browse files
panbhattRomakita
authored andcommitted
fix: fix log rotation
Fixed #146
1 parent d972670 commit d67d067

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

packages/file/src/FileAppender.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ export class FileAppender extends BaseAppender {
117117
numBackups = numBackups === undefined ? 5 : numBackups;
118118
// there has to be at least one backup if logSize has been specified
119119
numBackups = numBackups === 0 ? 1 : numBackups;
120-
120+
this.config.maxSize = logSize; // this needs to be added as streamroller uses maxSize while tsed is using maxLogSize as logSize
121121
this.writer = this.openTheStream(file, logSize, numBackups, pattern, this.config);
122122
// On SIGHUP, close and reopen all files. This allows this appender to work with
123123
// logrotate. Note that if you are using logrotate, you should not set
@@ -138,7 +138,9 @@ export class FileAppender extends BaseAppender {
138138
*/
139139
private openTheStream(file: string, fileSize: number | undefined, numFiles: number, pattern: string | undefined, options: any) {
140140
let stream = null;
141-
if (pattern) {
141+
if (pattern && fileSize && file) {
142+
stream = new streams.RollingFileWriteStream(file, options); // Since the whole object is present in options, pattern would be taken from it.
143+
} else if (pattern) {
142144
stream = new streams.DateRollingFileStream(file, pattern, options);
143145
} else {
144146
stream = new streams.RollingFileStream(file, fileSize, numFiles, options);

0 commit comments

Comments
 (0)