Skip to content

Commit 3759362

Browse files
author
Hweinstock
committed
refactor(logging): rename flush to end to make it clear the stream is closed
1 parent bd66719 commit 3759362

4 files changed

Lines changed: 6 additions & 4 deletions

File tree

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ process.exit(
5555
.error();
5656
throw e;
5757
} finally {
58-
await rootLogger.flush();
58+
await rootLogger.end();
5959
}
6060
}),
6161
);

src/logging/fileLogger.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@ function wrapWinstonLogger(
2727
error: log("error"),
2828
child: (childBindings) =>
2929
wrapWinstonLogger(winstonLogger, transport, { ...bindings, ...childBindings }),
30-
flush: () =>
30+
end: () =>
3131
new Promise<void>((resolve) => {
3232
transport.on("finish", resolve);
33+
// note: we prefer close over end since close calls end on the stream internally: https://github.com/winstonjs/winston-daily-rotate-file/blob/a1a4668cfea77476cd6a4a11f038c2aac9d10741/daily-rotate-file.js#L201-L207
3334
if (transport.close) transport.close();
3435
}),
3536
};

src/logging/types.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,6 @@ export interface Logger {
2727
/** An extension of {@link Logger} that writes logs asynchronously and requires output to be flushed */
2828
export interface AsyncLogger extends Logger {
2929
child: (bindings: LoggerBindings) => AsyncLogger;
30-
flush: () => Promise<void>;
30+
/** Flushes the pending logs and closes the underlying logging streams **/
31+
end: () => Promise<void>;
3132
}

src/middleware/withLogging.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ describe("withLogging", () => {
2121
});
2222

2323
afterEach(async () => {
24-
await logger.flush();
24+
await logger.end();
2525
await rm(tempDir, { recursive: true, force: true });
2626
});
2727

0 commit comments

Comments
 (0)