Skip to content

Commit

Permalink
Merge pull request #5 from JayPaulinCodes/fix/fileAutoCloseIssues
Browse files Browse the repository at this point in the history
File Closing Issues
  • Loading branch information
JayPaulinCodes authored Mar 7, 2024
2 parents 0bca965 + 1a9e971 commit 118ce76
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/classes/Logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ export class Logger {
const filePath = this.options.output.file.outputDirectory + fileName;
const oldStream = this.writeStream;
const newStream = createWriteStream(filePath, { flags: "wx", encoding: "utf8" });
this.writeStream = null;

// Wait for the new file to open
newStream.on("open", () => {
Expand All @@ -106,10 +107,6 @@ export class Logger {
oldStream.end();
}
});

newStream.once("close", () => {
this.writeStream = null;
});

return;
}
Expand All @@ -133,7 +130,8 @@ export class Logger {
private scheduleLogFileSwitch(): void {
// Previously was: 86400000 - (((Date.now() + 5000) % 86400000) - 5000)
const MS_24_HRS = 24 * 60 * 60 * 1000; // 86400000
const MS_DELAY = MS_24_HRS - (Date.now() % MS_24_HRS);
const DATE = Date.now() + (new Date().getTimezoneOffset() * (this.options.output.useZuluTime ? 0 : -60000));
const MS_DELAY = MS_24_HRS - (DATE % MS_24_HRS);
this.fileSwitchTimeout = setTimeout(() => {
try {
this.setUpLogFile();
Expand Down

0 comments on commit 118ce76

Please sign in to comment.