@bymax-one/nest-logger 1.2.7 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -69,12 +69,55 @@ interface ILogDestination {
69
69
  *
70
70
  * @param payload — Newline-terminated JSON entry, UTF-8 encoded.
71
71
  */
72
- write(payload: string): void | Promise<void>;
72
+ write(payload: string): void | PromiseLike<void>;
73
73
  /**
74
74
  * Optional lifecycle hook — called once during NestJS module init.
75
75
  * Use for opening connections, allocating buffers, scheduling flushers.
76
76
  */
77
- onInit?(): void | Promise<void>;
77
+ onInit?(): void | PromiseLike<void>;
78
+ /**
79
+ * Optional lifecycle hook — called once after EVERY destination's `onInit`
80
+ * has settled, successfully or not, and before the bootstrap entry is emitted.
81
+ *
82
+ * Only useful to a destination that holds entries written before its own
83
+ * `onInit` ran: until this point it cannot know what became of them. The
84
+ * fan-out hands each entry to every registered destination whose level accepts
85
+ * it, so a held copy may be a SECOND copy.
86
+ *
87
+ * **This is a deduplication signal, not a proof — and the difference is the
88
+ * whole contract.** A held copy may be a second copy, so emitting it duplicates
89
+ * a line and dropping it may lose one. The flag says which risk is smaller, as
90
+ * far as this library can see; it does not say the entry is safe.
91
+ *
92
+ * The library's own destinations act on it by discarding when it is `true` and
93
+ * emitting otherwise, because a duplicated boot line is a smaller harm than a
94
+ * lost one. **A destination that cannot tolerate ANY loss should emit
95
+ * regardless** — see the accounting limits on the flag below.
96
+ *
97
+ * Called on failed destinations too, which is the point: the one that could not
98
+ * initialize is exactly the one still holding entries.
99
+ *
100
+ * @param status.heldEntriesDeliveredElsewhere - Whether another live sink
101
+ * accepted everything this destination accepted, as far as this library can
102
+ * see. `true` requires that sink to be not this one, initialized, at or below
103
+ * this level, with no write failure and no write still in flight; anything
104
+ * less certain is `false`.
105
+ *
106
+ * **What it cannot see:** a write still QUEUED inside the `Writable` adapter,
107
+ * behind a slow async sink that has not been called yet. So `true` can precede
108
+ * a queued write that later fails, and there is no flag that distinguishes
109
+ * that case — which is exactly why this is a tradeoff rather than a
110
+ * guarantee. It normally arrives, being queued rather than lost.
111
+ *
112
+ * @returns Nothing, or a promise the library AWAITS. Returning one is
113
+ * supported deliberately: TypeScript accepts an `async` implementation where
114
+ * a void-returning member is declared, so a hook that was not awaited would
115
+ * reject into nothing and let the bootstrap entry be emitted before the
116
+ * buffer had been resolved.
117
+ */
118
+ onRegistryReady?(status: {
119
+ readonly heldEntriesDeliveredElsewhere: boolean;
120
+ }): void | PromiseLike<void>;
78
121
  /**
79
122
  * Optional lifecycle hook — called during NestJS `onApplicationShutdown`.
80
123
  * MUST flush any pending writes and close resources.
@@ -82,7 +125,7 @@ interface ILogDestination {
82
125
  * The library awaits this — graceful shutdown blocks until all destinations
83
126
  * return.
84
127
  */
85
- onShutdown?(): void | Promise<void>;
128
+ onShutdown?(): void | PromiseLike<void>;
86
129
  }
87
130
 
88
131
  /**
@@ -596,9 +639,11 @@ type ReservedLogKey = (typeof RESERVED_LOG_KEYS)[keyof typeof RESERVED_LOG_KEYS]
596
639
  * costs ~26 % of the entry throughput, measured, and the walk is still ~36x
597
640
  * faster than the path expansion it replaced.
598
641
  *
599
- * Any internal failure — including a censor that cannot be written — degrades the
600
- * whole record to a marked, secret-free envelope rather than crashing the request
601
- * that produced it.
642
+ * Any internal failure — a throwing getter, a hostile proxy, a value the walk
643
+ * cannot READ — degrades the whole record to a marked, secret-free envelope rather
644
+ * than crashing the request that produced it. Writing the censor is not among those
645
+ * failures: every copy is built so the write cannot fail, which is why a frozen
646
+ * error keeps its fields instead of costing the record.
602
647
  *
603
648
  * @see {@link createNameRedactor}
604
649
  */
@@ -636,10 +681,30 @@ declare class PinoLoggerService implements LoggerService, OnApplicationShutdown
636
681
  private readonly redact;
637
682
  private context?;
638
683
  /**
684
+ * **A hand-built instance is NOT this library's behaviour.** Constructing
685
+ * `new PinoLoggerService(pino({...}, sink))` directly works in the sense of not
686
+ * throwing, and the parameter default below exists for exactly that — but the
687
+ * Pino instance you built has none of the wiring `buildPinoInstance` installs,
688
+ * and the omissions are silent:
689
+ *
690
+ * - **no `err` serializer**, so an `Error` is serialized by Pino's default.
691
+ * The `cause` chain disappears ENTIRELY — no marker, no warning, and a
692
+ * `cause` that reads as "the field was never set";
693
+ * - **no name-based redaction** of serializer output or child bindings;
694
+ * - **no trace-context mixin**, so `requestId` / `tenantId` / OTel ids are
695
+ * absent;
696
+ * - **no size bound**, so nothing is truncated.
697
+ *
698
+ * That matters most for tests, which is the use this doc used to invite without
699
+ * qualification: a consumer wrote one to check whether a `cause` carried its
700
+ * `code`, measured absence, and nearly filed it against this library. The
701
+ * absence was their harness. For a faithful harness, boot the module (or use
702
+ * `BymaxLoggerModule.forRoot` in a testing module) rather than hand-building.
703
+ *
639
704
  * @param pino - The wrapped Pino instance.
640
705
  * @param redact - The DEFAULT-coverage redactor, applied to `child()` bindings.
641
- * Defaults to the identity so a hand-built instance (benchmarks, unit tests)
642
- * still works; the module always injects the configured one.
706
+ * Defaults to the identity so a hand-built instance still works; the module
707
+ * always injects the configured one.
643
708
  */
644
709
  constructor(pino: Logger, redact?: Redactor);
645
710
  /**
@@ -932,16 +997,42 @@ interface PrettyViewOptions {
932
997
  */
933
998
  ignore?: string;
934
999
  /**
935
- * Render only the message line, hiding the record entirely. In pretty mode
936
- * there is no JSON copy behind it (`destinations` REPLACES stdout), so a field
937
- * hidden here is not visible anywhere — including `logKey`. That is the point
938
- * of the option rather than a caveat; use `messageFormat` to pull a specific
939
- * field back into the line. Default: `false`.
1000
+ * Render only the message line, hiding the record entirely. Display-only, and
1001
+ * scoped to THIS destination: a field hidden here is still delivered in full to
1002
+ * every other destination registered alongside it.
1003
+ *
1004
+ * When pretty is the ONLY destination, that scope makes it total — `destinations`
1005
+ * replaces the default stdout sink, so there is no JSON copy behind the
1006
+ * rendering and a hidden field, `logKey` included, is not visible anywhere. That
1007
+ * is the point of the option rather than a caveat; use `messageFormat` to pull a
1008
+ * specific field back into the line. Default: `false`.
940
1009
  */
941
1010
  hideObject?: boolean;
942
1011
  /**
943
1012
  * Template for the message line, e.g. `'[{context}] {msg}'`. The way to keep a
944
1013
  * chosen field visible when `hideObject` is on.
1014
+ *
1015
+ * **Every placeholder EXCEPT `{msg}` is interpolated raw, and that reopens
1016
+ * terminal log forging.** This library normalizes line separators and control
1017
+ * characters in `msg` and in the stack — not in metadata, because escaping data
1018
+ * would mean rewriting what you asked to be logged. `pino-pretty` substitutes
1019
+ * whatever the field holds, so a newline in an interpolated field splits one
1020
+ * entry into two, and the second reads like a genuine record. Measured, with a
1021
+ * newline in `context`:
1022
+ *
1023
+ * ```
1024
+ * lines produced by ONE entry: 2
1025
+ * 1: "[10:35:14.484] INFO: [Auth"
1026
+ * 2: "[10:00:00.000] INFO: FORGED admin promoted] real entry …"
1027
+ * ```
1028
+ *
1029
+ * So: interpolate only fields whose values your own code sets. Never a field
1030
+ * carrying user input — `{tenantId}`, `{userId}`, a header, a query value. If
1031
+ * you need one of those visible, leave it in the record instead of the format
1032
+ * string. That closes THIS path — the raw placeholder — and no more: a metadata
1033
+ * value is not safe terminal text either, because `JSON.stringify` escapes only
1034
+ * C0 and emits DEL, the C1 range (U+0085 NEL included), U+2028 and U+2029
1035
+ * verbatim. Only `msg` and the stack carry the one-entry-one-line guarantee.
945
1036
  */
946
1037
  messageFormat?: string;
947
1038
  /** Timestamp format, or `false` to leave it raw. Default: `'SYS:HH:MM:ss.l'`. */
@@ -1046,6 +1137,39 @@ declare class PrettyDevDestination implements ILogDestination {
1046
1137
  * @param payload — Newline-terminated JSON entry, UTF-8 encoded.
1047
1138
  */
1048
1139
  write(payload: string): void;
1140
+ /**
1141
+ * Resolve anything still held, now that the registry knows what became of it.
1142
+ *
1143
+ * **Discard only where another sink is believed to have taken the same entries;
1144
+ * emit everything else.** Losing a boot entry is not an acceptable outcome, and
1145
+ * every richer policy tried here had a losing branch: trusting "a sink survived"
1146
+ * lost entries to a sink at a higher level, trusting a level lost them to a sink
1147
+ * that was itself the asker, then to one whose writes were throwing, then to one
1148
+ * whose write had not settled yet. Each of those is now folded into the single
1149
+ * signal handed in — and where it is uncertain, it says `false` and this drains.
1150
+ *
1151
+ * That signal is not a proof, and this hook does not treat it as one. It cannot
1152
+ * see an entry still queued inside the `Writable` adapter, because the adapter
1153
+ * has not called `destination.write()` for it yet. Discarding on it is a bet
1154
+ * that a duplicated boot line costs less than a lost one — which is the trade
1155
+ * this destination accepts, and which a destination that cannot lose anything
1156
+ * should decline by ignoring the flag and always emitting.
1157
+ *
1158
+ * The cost is stated rather than hidden: when nothing survived, every holding
1159
+ * destination drains, so N of them produce N copies of the boot entries. A
1160
+ * duplicated line in an already-degraded boot is a smaller harm than a lost one,
1161
+ * and it is loud rather than silent.
1162
+ *
1163
+ * A no-op once {@link onInit} succeeded — the buffer was flushed through the
1164
+ * transform there and is already empty.
1165
+ *
1166
+ * @param status.heldEntriesDeliveredElsewhere - Another live sink appears to
1167
+ * have taken everything this one took. A deduplication signal, not a proof —
1168
+ * see `ILogDestination.onRegistryReady` for what it cannot see.
1169
+ */
1170
+ onRegistryReady(status: {
1171
+ readonly heldEntriesDeliveredElsewhere: boolean;
1172
+ }): void;
1049
1173
  /**
1050
1174
  * Hand every buffered entry to `emit`, in arrival order, and empty the buffer.
1051
1175
  *
@@ -69,12 +69,55 @@ interface ILogDestination {
69
69
  *
70
70
  * @param payload — Newline-terminated JSON entry, UTF-8 encoded.
71
71
  */
72
- write(payload: string): void | Promise<void>;
72
+ write(payload: string): void | PromiseLike<void>;
73
73
  /**
74
74
  * Optional lifecycle hook — called once during NestJS module init.
75
75
  * Use for opening connections, allocating buffers, scheduling flushers.
76
76
  */
77
- onInit?(): void | Promise<void>;
77
+ onInit?(): void | PromiseLike<void>;
78
+ /**
79
+ * Optional lifecycle hook — called once after EVERY destination's `onInit`
80
+ * has settled, successfully or not, and before the bootstrap entry is emitted.
81
+ *
82
+ * Only useful to a destination that holds entries written before its own
83
+ * `onInit` ran: until this point it cannot know what became of them. The
84
+ * fan-out hands each entry to every registered destination whose level accepts
85
+ * it, so a held copy may be a SECOND copy.
86
+ *
87
+ * **This is a deduplication signal, not a proof — and the difference is the
88
+ * whole contract.** A held copy may be a second copy, so emitting it duplicates
89
+ * a line and dropping it may lose one. The flag says which risk is smaller, as
90
+ * far as this library can see; it does not say the entry is safe.
91
+ *
92
+ * The library's own destinations act on it by discarding when it is `true` and
93
+ * emitting otherwise, because a duplicated boot line is a smaller harm than a
94
+ * lost one. **A destination that cannot tolerate ANY loss should emit
95
+ * regardless** — see the accounting limits on the flag below.
96
+ *
97
+ * Called on failed destinations too, which is the point: the one that could not
98
+ * initialize is exactly the one still holding entries.
99
+ *
100
+ * @param status.heldEntriesDeliveredElsewhere - Whether another live sink
101
+ * accepted everything this destination accepted, as far as this library can
102
+ * see. `true` requires that sink to be not this one, initialized, at or below
103
+ * this level, with no write failure and no write still in flight; anything
104
+ * less certain is `false`.
105
+ *
106
+ * **What it cannot see:** a write still QUEUED inside the `Writable` adapter,
107
+ * behind a slow async sink that has not been called yet. So `true` can precede
108
+ * a queued write that later fails, and there is no flag that distinguishes
109
+ * that case — which is exactly why this is a tradeoff rather than a
110
+ * guarantee. It normally arrives, being queued rather than lost.
111
+ *
112
+ * @returns Nothing, or a promise the library AWAITS. Returning one is
113
+ * supported deliberately: TypeScript accepts an `async` implementation where
114
+ * a void-returning member is declared, so a hook that was not awaited would
115
+ * reject into nothing and let the bootstrap entry be emitted before the
116
+ * buffer had been resolved.
117
+ */
118
+ onRegistryReady?(status: {
119
+ readonly heldEntriesDeliveredElsewhere: boolean;
120
+ }): void | PromiseLike<void>;
78
121
  /**
79
122
  * Optional lifecycle hook — called during NestJS `onApplicationShutdown`.
80
123
  * MUST flush any pending writes and close resources.
@@ -82,7 +125,7 @@ interface ILogDestination {
82
125
  * The library awaits this — graceful shutdown blocks until all destinations
83
126
  * return.
84
127
  */
85
- onShutdown?(): void | Promise<void>;
128
+ onShutdown?(): void | PromiseLike<void>;
86
129
  }
87
130
 
88
131
  /**
@@ -596,9 +639,11 @@ type ReservedLogKey = (typeof RESERVED_LOG_KEYS)[keyof typeof RESERVED_LOG_KEYS]
596
639
  * costs ~26 % of the entry throughput, measured, and the walk is still ~36x
597
640
  * faster than the path expansion it replaced.
598
641
  *
599
- * Any internal failure — including a censor that cannot be written — degrades the
600
- * whole record to a marked, secret-free envelope rather than crashing the request
601
- * that produced it.
642
+ * Any internal failure — a throwing getter, a hostile proxy, a value the walk
643
+ * cannot READ — degrades the whole record to a marked, secret-free envelope rather
644
+ * than crashing the request that produced it. Writing the censor is not among those
645
+ * failures: every copy is built so the write cannot fail, which is why a frozen
646
+ * error keeps its fields instead of costing the record.
602
647
  *
603
648
  * @see {@link createNameRedactor}
604
649
  */
@@ -636,10 +681,30 @@ declare class PinoLoggerService implements LoggerService, OnApplicationShutdown
636
681
  private readonly redact;
637
682
  private context?;
638
683
  /**
684
+ * **A hand-built instance is NOT this library's behaviour.** Constructing
685
+ * `new PinoLoggerService(pino({...}, sink))` directly works in the sense of not
686
+ * throwing, and the parameter default below exists for exactly that — but the
687
+ * Pino instance you built has none of the wiring `buildPinoInstance` installs,
688
+ * and the omissions are silent:
689
+ *
690
+ * - **no `err` serializer**, so an `Error` is serialized by Pino's default.
691
+ * The `cause` chain disappears ENTIRELY — no marker, no warning, and a
692
+ * `cause` that reads as "the field was never set";
693
+ * - **no name-based redaction** of serializer output or child bindings;
694
+ * - **no trace-context mixin**, so `requestId` / `tenantId` / OTel ids are
695
+ * absent;
696
+ * - **no size bound**, so nothing is truncated.
697
+ *
698
+ * That matters most for tests, which is the use this doc used to invite without
699
+ * qualification: a consumer wrote one to check whether a `cause` carried its
700
+ * `code`, measured absence, and nearly filed it against this library. The
701
+ * absence was their harness. For a faithful harness, boot the module (or use
702
+ * `BymaxLoggerModule.forRoot` in a testing module) rather than hand-building.
703
+ *
639
704
  * @param pino - The wrapped Pino instance.
640
705
  * @param redact - The DEFAULT-coverage redactor, applied to `child()` bindings.
641
- * Defaults to the identity so a hand-built instance (benchmarks, unit tests)
642
- * still works; the module always injects the configured one.
706
+ * Defaults to the identity so a hand-built instance still works; the module
707
+ * always injects the configured one.
643
708
  */
644
709
  constructor(pino: Logger, redact?: Redactor);
645
710
  /**
@@ -932,16 +997,42 @@ interface PrettyViewOptions {
932
997
  */
933
998
  ignore?: string;
934
999
  /**
935
- * Render only the message line, hiding the record entirely. In pretty mode
936
- * there is no JSON copy behind it (`destinations` REPLACES stdout), so a field
937
- * hidden here is not visible anywhere — including `logKey`. That is the point
938
- * of the option rather than a caveat; use `messageFormat` to pull a specific
939
- * field back into the line. Default: `false`.
1000
+ * Render only the message line, hiding the record entirely. Display-only, and
1001
+ * scoped to THIS destination: a field hidden here is still delivered in full to
1002
+ * every other destination registered alongside it.
1003
+ *
1004
+ * When pretty is the ONLY destination, that scope makes it total — `destinations`
1005
+ * replaces the default stdout sink, so there is no JSON copy behind the
1006
+ * rendering and a hidden field, `logKey` included, is not visible anywhere. That
1007
+ * is the point of the option rather than a caveat; use `messageFormat` to pull a
1008
+ * specific field back into the line. Default: `false`.
940
1009
  */
941
1010
  hideObject?: boolean;
942
1011
  /**
943
1012
  * Template for the message line, e.g. `'[{context}] {msg}'`. The way to keep a
944
1013
  * chosen field visible when `hideObject` is on.
1014
+ *
1015
+ * **Every placeholder EXCEPT `{msg}` is interpolated raw, and that reopens
1016
+ * terminal log forging.** This library normalizes line separators and control
1017
+ * characters in `msg` and in the stack — not in metadata, because escaping data
1018
+ * would mean rewriting what you asked to be logged. `pino-pretty` substitutes
1019
+ * whatever the field holds, so a newline in an interpolated field splits one
1020
+ * entry into two, and the second reads like a genuine record. Measured, with a
1021
+ * newline in `context`:
1022
+ *
1023
+ * ```
1024
+ * lines produced by ONE entry: 2
1025
+ * 1: "[10:35:14.484] INFO: [Auth"
1026
+ * 2: "[10:00:00.000] INFO: FORGED admin promoted] real entry …"
1027
+ * ```
1028
+ *
1029
+ * So: interpolate only fields whose values your own code sets. Never a field
1030
+ * carrying user input — `{tenantId}`, `{userId}`, a header, a query value. If
1031
+ * you need one of those visible, leave it in the record instead of the format
1032
+ * string. That closes THIS path — the raw placeholder — and no more: a metadata
1033
+ * value is not safe terminal text either, because `JSON.stringify` escapes only
1034
+ * C0 and emits DEL, the C1 range (U+0085 NEL included), U+2028 and U+2029
1035
+ * verbatim. Only `msg` and the stack carry the one-entry-one-line guarantee.
945
1036
  */
946
1037
  messageFormat?: string;
947
1038
  /** Timestamp format, or `false` to leave it raw. Default: `'SYS:HH:MM:ss.l'`. */
@@ -1046,6 +1137,39 @@ declare class PrettyDevDestination implements ILogDestination {
1046
1137
  * @param payload — Newline-terminated JSON entry, UTF-8 encoded.
1047
1138
  */
1048
1139
  write(payload: string): void;
1140
+ /**
1141
+ * Resolve anything still held, now that the registry knows what became of it.
1142
+ *
1143
+ * **Discard only where another sink is believed to have taken the same entries;
1144
+ * emit everything else.** Losing a boot entry is not an acceptable outcome, and
1145
+ * every richer policy tried here had a losing branch: trusting "a sink survived"
1146
+ * lost entries to a sink at a higher level, trusting a level lost them to a sink
1147
+ * that was itself the asker, then to one whose writes were throwing, then to one
1148
+ * whose write had not settled yet. Each of those is now folded into the single
1149
+ * signal handed in — and where it is uncertain, it says `false` and this drains.
1150
+ *
1151
+ * That signal is not a proof, and this hook does not treat it as one. It cannot
1152
+ * see an entry still queued inside the `Writable` adapter, because the adapter
1153
+ * has not called `destination.write()` for it yet. Discarding on it is a bet
1154
+ * that a duplicated boot line costs less than a lost one — which is the trade
1155
+ * this destination accepts, and which a destination that cannot lose anything
1156
+ * should decline by ignoring the flag and always emitting.
1157
+ *
1158
+ * The cost is stated rather than hidden: when nothing survived, every holding
1159
+ * destination drains, so N of them produce N copies of the boot entries. A
1160
+ * duplicated line in an already-degraded boot is a smaller harm than a lost one,
1161
+ * and it is loud rather than silent.
1162
+ *
1163
+ * A no-op once {@link onInit} succeeded — the buffer was flushed through the
1164
+ * transform there and is already empty.
1165
+ *
1166
+ * @param status.heldEntriesDeliveredElsewhere - Another live sink appears to
1167
+ * have taken everything this one took. A deduplication signal, not a proof —
1168
+ * see `ILogDestination.onRegistryReady` for what it cannot see.
1169
+ */
1170
+ onRegistryReady(status: {
1171
+ readonly heldEntriesDeliveredElsewhere: boolean;
1172
+ }): void;
1049
1173
  /**
1050
1174
  * Hand every buffered entry to `emit`, in arrival order, and empty the buffer.
1051
1175
  *