@bymax-one/nest-logger 1.4.10 → 1.4.11

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.
package/CHANGELOG.md CHANGED
@@ -11,6 +11,64 @@ heading here.
11
11
 
12
12
  ## [Unreleased]
13
13
 
14
+ ## [1.4.11] - 2026-11-08
15
+
16
+ ### Added
17
+
18
+ - **`errorOwnFields: 'all' | 'safe'` and `errorOwnFieldNames`.** Node's own errors carry values in
19
+ their own fields: a failed child process has its `stdout`, `stderr` and `output`, an
20
+ `AssertionError` its `actual` and `expected`, a file system error its `path`. A list of field
21
+ names to drop cannot name them all, so `'safe'` writes only an allow-list of operational
22
+ names (listed in the README) plus the names in `errorOwnFieldNames`, at
23
+ every depth and for an `Error` nested in the metadata. The default stays `'all'` in the 1.x line,
24
+ where every own field is written as before. Under `'safe'` the redaction also writes plain data: a
25
+ function or a symbol is omitted, a Buffer or typed array anywhere in the record is its size
26
+ marker, an `Error` is written from its own fields (its `toJSON` is not called), and a custom
27
+ serializer receives it as a plain error-like object instead of an `Error` instance.
28
+
29
+ ### Fixed
30
+
31
+ - **A Buffer in the metadata no longer makes the log call throw under `redactStrategy: 'paths'`.**
32
+ Pino's path redaction cannot read a `Buffer`; the record is now walked first, so it never meets
33
+ one.
34
+ - **An error from another realm is written as the error it is.** An `Error` made in a `vm` context,
35
+ or by a Node core module under a test runner, is not an `instanceof Error`, so it was read as a
36
+ plain object whose `name` and `message` were lost and came out as `UnknownError`. It is now
37
+ recognised with `util.types.isNativeError` as well as `instanceof`.
38
+
39
+ ### Changed
40
+
41
+ - **A binary value is written as its size.** A Buffer, a typed array or a `DataView` anywhere in the
42
+ record, in an error's own fields, or as a member of an array there (how a child process's `output`
43
+ arrives), was written as an object of its bytes. It is now `"[Binary 42 bytes]"`, in both modes
44
+ and under both redaction strategies. Under `redactStrategy: 'paths'` the record is now walked once
45
+ for this, so the walk's depth ceiling (100) and visit budget apply there. With every redaction
46
+ turned off (`shouldDisableDefaultRedact`, no `redactPaths`, and `errorOwnFields` not `'safe'`)
47
+ nothing walks the record and a Buffer is written as Pino writes it.
48
+ - **A message is written at most 16384 characters long.** The `msg` of every call, the `message` of
49
+ a serialized error and of each `cause` or `errors` link, the `message` of a nested `Error` in the
50
+ metadata, the semconv `exception.message`, the `errorMessage` of a 4xx access-log entry, and the
51
+ messages in the reports of a failed destination or of `pino-pretty` were written whole, so a
52
+ message of 5 million characters made a line of 5 million characters. A message is now cut at 16384
53
+ characters, after its line breaks and control characters are escaped, and ends with
54
+ `…[truncated]`, as a stack does; the limit is one number for both. A cut never leaves half of a
55
+ surrogate pair. The name of an error (the serialized `type`, the semconv `exception.type` and
56
+ `error.type`, and the name in a failure report) is cut the same way. Metadata strings are the
57
+ caller's data and are not cut.
58
+
59
+ #### Apply to a derived backend
60
+
61
+ Set `errorOwnFields: 'safe'`, and list in `errorOwnFieldNames` any own field you alert on that is
62
+ not in the default list (`orderId`, or `path` if a path is not data to you). Without it the error
63
+ entries keep every own field, as before, except that bytes are written as a size.
64
+
65
+ A Buffer you log on purpose is now written as `"[Binary N bytes]"` wherever it sits in the record;
66
+ convert it first (`buffer.toString('base64')`) to keep its content in the line.
67
+
68
+ A message longer than 16384 characters, such as the message of an
69
+ `assert` failure over two large objects, is cut and ends with `…[truncated]`; an ordinary message
70
+ is far shorter and is written as before.
71
+
14
72
  ## [1.4.10] - 2026-11-06
15
73
 
16
74
  ### Security
@@ -2458,7 +2516,8 @@ published `dist/` is identical — no runtime behaviour changes for consumers.
2458
2516
  - Professional CI suite: `ci.yml`, `bench.yml`, `codeql.yml`, `scorecard.yml`,
2459
2517
  `release.yml`, Dependabot, and issue templates
2460
2518
 
2461
- [Unreleased]: https://github.com/bymaxone/nest-logger/compare/v1.4.10...HEAD
2519
+ [Unreleased]: https://github.com/bymaxone/nest-logger/compare/v1.4.11...HEAD
2520
+ [1.4.11]: https://github.com/bymaxone/nest-logger/compare/v1.4.10...v1.4.11
2462
2521
  [1.4.10]: https://github.com/bymaxone/nest-logger/compare/v1.4.9...v1.4.10
2463
2522
  [1.4.9]: https://github.com/bymaxone/nest-logger/compare/v1.4.8...v1.4.9
2464
2523
  [1.4.8]: https://github.com/bymaxone/nest-logger/compare/v1.4.7...v1.4.8
package/README.md CHANGED
@@ -731,11 +731,28 @@ written. The fields `args` and `parameters` are omitted, a `command` object is r
731
731
  the statement (its other fields stay), because the redaction
732
732
  matches key names and cannot see a value inside a string.
733
733
 
734
+ **Own fields of an error: `errorOwnFields`.** Node's own errors carry values: a failed child process has its `stdout`, `stderr` and `output` (Buffers), an `AssertionError` its `actual` and `expected`, a file system error its `path`, a `URL` error its `input`. A list of names to drop cannot name them all, so the choice is yours:
735
+
736
+ - `errorOwnFields: 'all'` (the default in 1.x) writes every own field as above. A binary value (a Buffer, a typed array or a `DataView`) is written as its size, such as `"[Binary 42 bytes]"`, never as bytes: as an own field of an error (a failed child process carries its `stdout`, `stderr` and `output` there), as a member of an array, and anywhere else in the record. See _Binary values_ below.
737
+ - `errorOwnFields: 'safe'` writes only `code`, `errno`, `syscall`, `signal`, `status`, `statusCode`, `address`, `port`, `hostname` and the PostgreSQL `constraint`, `table`, `column`, `schema` and `routine`, plus the names in `errorOwnFieldNames`, at every depth and for an `Error` nested in the metadata. `path` is not on the list: add it if a path is not data to you. Under `'safe'` what the redaction writes is plain data, with nothing left to run later. An `Error` is written from its own fields: a `toJSON` it has (an HTTP client's, which may carry the request) is not called, and a serializer receives it as a plain error-like object (`name`, `message`, `stack`, `cause`, `errors` and the allowed fields) instead of an `Error` instance. Any other `toJSON` is called once, as `JSON.stringify` would, and its result is censored. A function or a symbol is omitted as `JSON.stringify` omits it, and a Buffer or a typed array anywhere in the record is written as its `[Binary N bytes]` marker. The `type`, `message`, `stack`, `cause` and `errors` the logger derives are always written. Names are matched exactly, case included. The recommended setting.
738
+
739
+ ```typescript
740
+ BymaxLoggerModule.forRoot({
741
+ service: { name: 'api', version: '1.0.0' },
742
+ errorOwnFields: 'safe',
743
+ errorOwnFieldNames: ['orderId']
744
+ })
745
+ ```
746
+
747
+ **Binary values.** A Buffer, a typed array or a `DataView` anywhere in the record is written as its size (`"[Binary 42 bytes]"`), in both modes and under both redaction strategies, whatever `toJSON` a subclass defines. This holds whenever the record is walked: with the default coverage, with any entry in `redactPaths`, and under `redactStrategy: 'paths'`, where the record is walked once for this and the walk's depth ceiling (100) and visit budget apply. If you turn every redaction off (`shouldDisableDefaultRedact: true`, no `redactPaths`, and `errorOwnFields` not `'safe'`), nothing walks the record, so the marker is off with it and a Buffer is written the way Pino writes it. To log the bytes of a Buffer on purpose, convert it first, for example `buffer.toString('base64')`.
748
+
749
+ Neither setting covers the `message`: Node writes the command line of a failed child process, arguments included, and what it printed to stderr into it, and the redaction matches key names, not text.
750
+
734
751
  When those properties cannot be read (a Proxy whose `ownKeys` throws, or a getter that throws), none of them is copied and the error node carries `_errorFieldsIncomplete: true`, so an entry without its `code` is never mistaken for a complete one.
735
752
 
736
753
  An `Error` that cannot be read at all does not cost the record its `logKey`, `userId` or metadata: the node is replaced by its sanitized form, which keeps `name` and `message` and carries the same marker unless `name` or `message` itself is unreadable, in which case it is `{ type: 'SanitizeFailed' }`. Filter on `err._errorFieldsIncomplete: true` or `SanitizeFailed` to find these entries.
737
754
 
738
- An `Error` nested in the metadata (under a key, inside an array, or inside another `Error`) is written as its own enumerable fields, censored by name (or as its `toJSON` decides), with `type`, `message`, `stack`, `cause` and `errors` added where the node has no key of that name. The added cause chain and `errors` are bounded as the root `err`'s are, each with a `_truncated` marker. A string `cause` is logged like a `message`: do not put secrets in either. Whatever sits under a record-root key that has a serializer, `err` or a key of `serializers`, reaches that serializer censored by name, with its `Error`s still instances, and what a serializer returns is written as returned, so an `Error` in that output stays `{}` (the arguments and quoted values of a failed driver call are omitted from it, as everywhere).
755
+ An `Error` nested in the metadata (under a key, inside an array, or inside another `Error`) is written as its own enumerable fields, censored by name (or as its `toJSON` decides, except under `errorOwnFields: 'safe'`, where an `Error` is written from its own fields and its `toJSON` is not called), with `type`, `message`, `stack`, `cause` and `errors` added where the node has no key of that name. The added cause chain and `errors` are bounded as the root `err`'s are, each with a `_truncated` marker. A string `cause` is logged like a `message`: do not put secrets in either. Whatever sits under a record-root key that has a serializer, `err` or a key of `serializers`, reaches that serializer censored by name, with its `Error`s still instances (under `errorOwnFields: 'safe'`, as plain data: see _Own fields of an error_), and what a serializer returns is written as returned, so an `Error` in that output stays `{}` (the arguments and quoted values of a failed driver call are omitted from it, as everywhere; plain data under `'safe'`).
739
756
 
740
757
  ### 7. Context propagation with `LogContextService`
741
758
 
@@ -783,27 +800,29 @@ Full options reference for `BymaxLoggerModule.forRoot(options)`:
783
800
 
784
801
  ### Top-level options
785
802
 
786
- | Option | Type | Default | Description |
787
- | ---------------------------- | --------------------------------------------- | --------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------ |
788
- | `service.name` | `string` | **Required** | Service name emitted in every log entry |
789
- | `service.version` | `string` | **Required** | Release version/SHA emitted in every log entry |
790
- | `service.namespace` | `string` | — | OTel `service.namespace` (**Stable**) — the group the service belongs to |
791
- | `service.instanceId` | `string` | — | OTel `service.instance.id` (**Stable**). **Never generated** — supply it from the platform. See [Resource identity](#6b-resource-identity) |
792
- | `service.environment` | `string` | `NODE_ENV` | OTel `deployment.environment.name` (**Stable**). The deprecated `deployment.environment` is never emitted |
793
- | `resourceFormat` | `'nested' \| 'flat'` | `'nested'` | Shape of the identity fields. `'flat'` emits the dotted attribute names verbatim |
794
- | `eventNameField` | `string \| false` | `'event.name'` | Field carrying the derived event name (`PAYMENT_FAILED` → `payment.failed`). `false` disables it |
795
- | `errorFormat` | `'pino' \| 'semconv' \| 'both'` | `'pino'` | `'both'` adds `exception.*` and `error.type` beside `err.*`; `'semconv'` replaces them |
796
- | `level` | `LogLevel` | `'info'` when `NODE_ENV=production`, else `'debug'` | Minimum log level. One of `fatal \| error \| warn \| info \| debug \| trace` |
797
- | `redactPaths` | `string[]` | `[]` | Additional `fast-redact` paths, applied on top of the default coverage |
798
- | `redactStrategy` | `'names' \| 'paths'` | `'names'` | Engine behind the DEFAULT set. `'paths'` restores the pre-1.2 `fast-redact` expansion (four-level ceiling, ~100× slower) |
799
- | `shouldDisableDefaultRedact` | `boolean` | `false` | Skip the default PII coverage entirely. ⚠️ Emits `LOGGER_BOOTSTRAP_WARNING` at startup — document why |
800
- | `redactCensor` | `string` | `'[REDACTED]'` | Replacement value written in place of every redacted field |
801
- | `maxEntrySizeBytes` | `number` | `65536` | UTF-8 byte ceiling per serialized field (`err` + any custom serializer); over it the value becomes a truncation envelope |
802
- | `isGlobal` | `boolean` | `true` | Register the module as `@Global()` |
803
- | `shouldUseAsNestLogger` | `boolean` | `true` | **Deprecated, not read.** Call `BymaxLoggerModule.useNestLogger(app)` in `main.ts` instead |
804
- | `serializers` | `Record<string, (input: unknown) => unknown>` | `{}` | Custom Pino serializers, merged with the defaults |
805
- | `timestamp` | `() => string` | `() => new Date().toISOString()` | Custom timestamp function |
806
- | `destinations` | `ILogDestination[]` | `[new DefaultStdoutDestination()]` | The sinks entries are written to. ⚠️ A non-empty list **replaces** that default — see [Destinations](#destinations-replace-stdout) |
803
+ | Option | Type | Default | Description |
804
+ | ---------------------------- | --------------------------------------------- | --------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
805
+ | `service.name` | `string` | **Required** | Service name emitted in every log entry |
806
+ | `service.version` | `string` | **Required** | Release version/SHA emitted in every log entry |
807
+ | `service.namespace` | `string` | — | OTel `service.namespace` (**Stable**) — the group the service belongs to |
808
+ | `service.instanceId` | `string` | — | OTel `service.instance.id` (**Stable**). **Never generated** — supply it from the platform. See [Resource identity](#6b-resource-identity) |
809
+ | `service.environment` | `string` | `NODE_ENV` | OTel `deployment.environment.name` (**Stable**). The deprecated `deployment.environment` is never emitted |
810
+ | `resourceFormat` | `'nested' \| 'flat'` | `'nested'` | Shape of the identity fields. `'flat'` emits the dotted attribute names verbatim |
811
+ | `eventNameField` | `string \| false` | `'event.name'` | Field carrying the derived event name (`PAYMENT_FAILED` → `payment.failed`). `false` disables it |
812
+ | `errorFormat` | `'pino' \| 'semconv' \| 'both'` | `'pino'` | `'both'` adds `exception.*` and `error.type` beside `err.*`; `'semconv'` replaces them |
813
+ | `level` | `LogLevel` | `'info'` when `NODE_ENV=production`, else `'debug'` | Minimum log level. One of `fatal \| error \| warn \| info \| debug \| trace` |
814
+ | `redactPaths` | `string[]` | `[]` | Additional `fast-redact` paths, applied on top of the default coverage |
815
+ | `redactStrategy` | `'names' \| 'paths'` | `'names'` | Engine behind the DEFAULT set. `'paths'` restores the pre-1.2 `fast-redact` expansion (four-level ceiling, ~100× slower) |
816
+ | `shouldDisableDefaultRedact` | `boolean` | `false` | Skip the default PII coverage entirely. ⚠️ Emits `LOGGER_BOOTSTRAP_WARNING` at startup — document why |
817
+ | `redactCensor` | `string` | `'[REDACTED]'` | Replacement value written in place of every redacted field |
818
+ | `maxEntrySizeBytes` | `number` | `65536` | UTF-8 byte ceiling per serialized field (`err` + any custom serializer); over it the value becomes a truncation envelope |
819
+ | `errorOwnFields` | `'all' \| 'safe'` | `'all'` | Which own fields of an error are written. `'all'` writes every one; `'safe'` writes an allow-list of operational names plus `errorOwnFieldNames` (see _Own fields of an error_ in section 6). A binary value is written as its size in both. Recommended: `'safe'` |
820
+ | `errorOwnFieldNames` | `readonly string[]` | `[]` | Own-field names `'safe'` writes beside its default list, matched exactly; ignored under `'all'` |
821
+ | `isGlobal` | `boolean` | `true` | Register the module as `@Global()` |
822
+ | `shouldUseAsNestLogger` | `boolean` | `true` | **Deprecated, not read.** Call `BymaxLoggerModule.useNestLogger(app)` in `main.ts` instead |
823
+ | `serializers` | `Record<string, (input: unknown) => unknown>` | `{}` | Custom Pino serializers, merged with the defaults |
824
+ | `timestamp` | `() => string` | `() => new Date().toISOString()` | Custom timestamp function |
825
+ | `destinations` | `ILogDestination[]` | `[new DefaultStdoutDestination()]` | The sinks entries are written to. ⚠️ A non-empty list **replaces** that default — see [Destinations](#destinations-replace-stdout) |
807
826
 
808
827
  ### `http` options
809
828
 
@@ -1248,7 +1267,7 @@ Every `write()` runs inside a try/catch. A destination that throws or rejects pr
1248
1267
 
1249
1268
  ### What redaction covers, and what it cannot
1250
1269
 
1251
- The walk is bounded: a container nested more than 100 levels deep is written as `[REDACTION_DEPTH_EXCEEDED]`, and a call that visits more than 200000 containers writes `[REDACTION_BUDGET_EXCEEDED]` in place of each further one. Nothing past either bound is passed through unwalked. A stack is written at most 16384 characters long and ends with `…[truncated]` when it was cut.
1270
+ The walk is bounded: a container nested more than 100 levels deep is written as `[REDACTION_DEPTH_EXCEEDED]`, and a call that visits more than 200000 containers writes `[REDACTION_BUDGET_EXCEEDED]` in place of each further one (only primitives beside them are kept; a container sibling after the budget is the marker too). Nothing past either bound is passed through unwalked. A stack or a message is written at most 16384 characters long and ends with `…[truncated]` when it was cut. A string under a metadata key is the caller's own data and is written as given: `maxEntrySizeBytes` bounds what a serializer returns, not a metadata string.
1252
1271
 
1253
1272
  Redaction here matches **field names**, not values. Under the default `redactStrategy: 'names'` a secret stored under a covered name is censored at any depth — under the legacy `'paths'` strategy the four-level `fast-redact` ceiling applies instead, and a deeper field is not covered. Either way, the same secret **embedded inside a string** under an uncovered name travels intact. Measured:
1254
1273