From 384169e3623657405e22109b7725755f1a1d254f Mon Sep 17 00:00:00 2001 From: Liam McLennan Date: Tue, 26 Mar 2024 14:29:27 +1000 Subject: [PATCH] Add a `flush` method to the stream --- example/example.ts | 2 ++ index.d.ts | 4 +++- pinoSeqStream.js | 5 +++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/example/example.ts b/example/example.ts index 0568bd7..b3edb57 100644 --- a/example/example.ts +++ b/example/example.ts @@ -13,3 +13,5 @@ logger.info("Hello Seq, from Pino"); const frLogger = logger.child({lang: "fr"}); frLogger.warn("au reviour"); + +stream.flush().then((_) => console.log('flushed')); \ No newline at end of file diff --git a/index.d.ts b/index.d.ts index 09f1f73..193997e 100644 --- a/index.d.ts +++ b/index.d.ts @@ -11,7 +11,9 @@ declare namespace PinoSeq { onError?: (e: Error) => void; } - function createStream(config: PinoSeq.SeqConfig): Writable; + function createStream(config: PinoSeq.SeqConfig): Writable & { + flush: () => Promise; + }; } export = PinoSeq; diff --git a/pinoSeqStream.js b/pinoSeqStream.js index 14fa097..5b4d84f 100644 --- a/pinoSeqStream.js +++ b/pinoSeqStream.js @@ -98,6 +98,11 @@ class PinoSeqStream extends stream.Writable { } } + flush() { + this.flushBuffer(); + return this._logger.flush(); + } + // Force the underlying logger to flush at the time of the call // and wait for pending writes to complete _final(callback) {