@warlock.js/logger 5.30.0 → 5.32.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.
- package/CHANGELOG.md +32 -5
- package/README.md +8 -11
- package/cjs/index.cjs +339 -31
- package/cjs/index.cjs.map +1 -1
- package/esm/channels/console-log.d.mts +2 -4
- package/esm/channels/console-log.d.mts.map +1 -1
- package/esm/channels/console-log.mjs.map +1 -1
- package/esm/channels/file-log.d.mts +130 -15
- package/esm/channels/file-log.d.mts.map +1 -1
- package/esm/channels/file-log.mjs +204 -23
- package/esm/channels/file-log.mjs.map +1 -1
- package/esm/channels/file-name-pattern.d.mts +15 -0
- package/esm/channels/file-name-pattern.d.mts.map +1 -0
- package/esm/channels/file-name-pattern.mjs +41 -0
- package/esm/channels/file-name-pattern.mjs.map +1 -0
- package/esm/channels/index.mjs +2 -2
- package/esm/channels/json-file-log.d.mts +1 -3
- package/esm/channels/json-file-log.d.mts.map +1 -1
- package/esm/channels/json-file-log.mjs +24 -5
- package/esm/channels/json-file-log.mjs.map +1 -1
- package/esm/channels/sentry-log.d.mts +7 -8
- package/esm/channels/sentry-log.d.mts.map +1 -1
- package/esm/channels/sentry-log.mjs.map +1 -1
- package/esm/index.d.mts +5 -3
- package/esm/index.mjs +3 -2
- package/esm/log-channel.d.mts +23 -3
- package/esm/log-channel.d.mts.map +1 -1
- package/esm/log-channel.mjs +22 -0
- package/esm/log-channel.mjs.map +1 -1
- package/esm/logger.d.mts +8 -5
- package/esm/logger.d.mts.map +1 -1
- package/esm/logger.mjs +12 -3
- package/esm/logger.mjs.map +1 -1
- package/esm/redact/default-keys.d.mts +3 -4
- package/esm/redact/default-keys.d.mts.map +1 -1
- package/esm/redact/escape-log-value.d.mts +25 -0
- package/esm/redact/escape-log-value.d.mts.map +1 -0
- package/esm/redact/escape-log-value.mjs +37 -0
- package/esm/redact/escape-log-value.mjs.map +1 -0
- package/esm/redact/index.mjs +2 -1
- package/esm/redact/mask-email.d.mts +3 -4
- package/esm/redact/mask-email.d.mts.map +1 -1
- package/esm/redact/redact.d.mts +3 -5
- package/esm/redact/redact.d.mts.map +1 -1
- package/esm/redact/redact.mjs.map +1 -1
- package/esm/types.d.mts +14 -14
- package/esm/types.d.mts.map +1 -1
- package/esm/utils/capture-unhandled-errors.d.mts +2 -3
- package/esm/utils/capture-unhandled-errors.d.mts.map +1 -1
- package/esm/utils/clear-message.d.mts +1 -2
- package/esm/utils/clear-message.d.mts.map +1 -1
- package/esm/utils/index.mjs +1 -1
- package/esm/utils/safe-json-stringify.d.mts +1 -2
- package/esm/utils/safe-json-stringify.d.mts.map +1 -1
- package/llms-full.txt +241 -141
- package/llms.txt +2 -2
- package/package.json +2 -2
- package/skills/capture-unhandled-errors/SKILL.md +9 -10
- package/skills/configure-logger/SKILL.md +7 -10
- package/skills/filter-log-entries/SKILL.md +2 -2
- package/skills/flush-logs-on-shutdown/SKILL.md +32 -13
- package/skills/index.md +4 -1
- package/skills/logger-basics/SKILL.md +18 -21
- package/skills/overview/SKILL.md +17 -6
- package/skills/pick-log-channel/SKILL.md +36 -24
- package/skills/redact-sensitive-log-fields/SKILL.md +48 -18
- package/skills/ship-logs-to-sentry/SKILL.md +18 -18
- package/skills/test-logging-code/SKILL.md +4 -2
- package/skills/write-custom-log-channel/SKILL.md +50 -17
package/CHANGELOG.md
CHANGED
|
@@ -4,15 +4,41 @@ All notable changes to `@warlock.js/logger` are documented in this file.
|
|
|
4
4
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). `@warlock.js/*` packages are released in lockstep — every package shares the same version number, so a version below may list only the changes that affected this package.
|
|
6
6
|
|
|
7
|
+
## 5.32.0 - 2026-10-18
|
|
8
|
+
|
|
9
|
+
### Changed
|
|
10
|
+
|
|
11
|
+
- Pin the package development compiler to TypeScript 7.0.2 and use explicit Node types and source roots with supported module resolution.
|
|
12
|
+
|
|
13
|
+
## 5.31.0 - 2026-10-18
|
|
14
|
+
|
|
15
|
+
### Upgrading
|
|
16
|
+
|
|
17
|
+
- **BREAKING:** `FileLog`/`JSONFileLog` dated file names are ISO dates that sort by name: `chunk: "daily"` writes `YYYY-MM-DD.log` (was `DD-MM-YYYY.log`) and `chunk: "hourly"` writes `YYYY-MM-DD-HH.log` (was `DD-MM-YYYY-HH-00-00-am.log`). Size-rotated archives default to `<file name>-YYYY-MM-DD-<epoch ms>`. After upgrading, a running daily channel starts a new file under the new name. To keep the old names, set `fileName: "{DD}-{MM}-{YYYY}"` (daily) and `rotateFileName: "{DD}-{MM}-{YYYY}"`. Tools that find logs by name (shippers, cron cleanups) need the new pattern; `retention` does not remove files with the old names.
|
|
18
|
+
- `rotateFileName` is now a `{YYYY}`/`{MM}`/`{DD}`/`{HH}`/`{mm}`/`{name}` pattern or a function of the rotation date, not a Day.js format. A value without tokens is used as is, as before; a Day.js format such as `"DD-MM-YYYY"` was always written literally and still is — use `"{DD}-{MM}-{YYYY}"`.
|
|
19
|
+
|
|
20
|
+
### Added
|
|
21
|
+
|
|
22
|
+
- `FileLog` `fileName` option: a pattern (`"app-{YYYY}-{MM}-{DD}"`, tokens `{YYYY}` `{MM}` `{DD}` `{HH}` `{mm}` `{name}` in local time) or a `(date) => string` function, evaluated at every write; it replaces the chunk's default name. `rotateFileName` takes the same forms and is rendered at each rotation (a getter passed in the config was read once, at construction, so every archive kept the boot date). Exported `FileNameOption`, `FileLogRetention`, `DAILY_FILE_NAME`, `HOURLY_FILE_NAME` and `ROTATE_FILE_NAME`.
|
|
23
|
+
- `FileLog` `retention: { maxFiles?, maxAgeDays?, match? }`: removes old log files on boot and whenever the channel starts a new file (a size rotation or a dated name rolling over), plus `channel.prune()` on demand. It only considers files in the log directory (each group directory with `groupBy`) whose names match the channel's file name pattern, keeps the file being written, and reports failures to `onChannelError` instead of throwing. A function `fileName` needs `retention.match`. Invalid `maxFiles`/`maxAgeDays` throw a `TypeError` at construction.
|
|
24
|
+
- `LogChannel.reportError(error, entry)` and `setErrorReporter(reporter)` (type `ChannelErrorReporter`): a channel reports failures outside `log()` to the `onChannelError` handler of the logger it was added to (`addChannel`, `setChannels`, `configure({ channels })`), or one stderr line without one.
|
|
25
|
+
- `escapeLogValue(value, { maxLength? })` makes client-controlled text safe inside a log line: CR/LF/tab become visible `\r`/`\n`/`\t`, other control characters (NUL, DEL, C1, U+2028/U+2029) become `\uXXXX`, ANSI escape sequences are removed, and `maxLength` cuts with a `…[truncated]` marker. A user agent or form field can no longer forge entries in console or file logs.
|
|
26
|
+
- Skills demonstrate email masking inside text, channel-error observation and bounded asynchronous log drains.
|
|
27
|
+
|
|
28
|
+
### Fixed
|
|
29
|
+
|
|
30
|
+
- With `groupBy`, size rotation renames the group file that grew too large instead of the ungrouped top-level file.
|
|
31
|
+
- A file name that throws while a buffer is written (a `fileName` function, or an overridden `fileName` getter) is reported as a failed write instead of leaving the channel stuck in its writing state; later writes go through.
|
|
32
|
+
|
|
7
33
|
## 5.30.0 - 2026-10-16
|
|
8
34
|
|
|
9
35
|
### Upgrading
|
|
10
36
|
|
|
11
|
-
- **BREAKING (types):** `log.info/warn/error/debug/success/fatal/log/assert` and the function `timer()` returns now return the logger synchronously instead of `Promise<this>`. Remove `await` before log calls (it is harmless but pointless) and any `.then()` chained on one; code that needs the write to finish calls `await log.flush()`.
|
|
37
|
+
- **BREAKING (types):** `log.info/warn/error/debug/success/fatal/log/assert` and the function `timer()` returns now return the logger synchronously instead of `Promise<this>`. Remove `await` before log calls (it is harmless but pointless) and any `.then()` chained on one; code that needs the write to finish calls `await log.flush()`. `warlock upgrade --from 5.29 --to 5.31.0` removes the `await`s and lists chained `.then()` calls (codemod `logger-sync-calls`).
|
|
12
38
|
|
|
13
39
|
### Changed
|
|
14
40
|
|
|
15
|
-
- Logging is fire-and-forget: level methods no longer return a promise, so `@typescript-eslint/no-floating-promises` no longer flags every call site
|
|
41
|
+
- Logging is fire-and-forget: level methods no longer return a promise, so `@typescript-eslint/no-floating-promises` no longer flags every call site.
|
|
16
42
|
- `log.flush()` drains every channel concurrently: each waits for its own in-flight async deliveries (including entries logged while the flush runs), then runs its `flush()`, so a hung network channel no longer holds up the file channel.
|
|
17
43
|
- `log.flush({ timeout })` is bounded: it resolves after `timeout` ms (default 5000, `DEFAULT_FLUSH_TIMEOUT_MS`; `Infinity` waits without a limit) and reports each channel still draining to the channel error handler. Before, one delivery that never settled made `flush()` (and a graceful shutdown awaiting it) wait forever.
|
|
18
44
|
- `maskEmailsInText` cuts text longer than `MASK_EMAILS_MAX_LENGTH` (16,384 characters) and marks the cut, so masking a huge cache key or message has a bounded cost.
|
|
@@ -20,7 +46,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
|
|
|
20
46
|
### Added
|
|
21
47
|
|
|
22
48
|
- `log.onChannelError(handler)` / `configure({ onChannelError })` and the `ChannelErrorHandler` type: receives a channel's sync throw or async rejection from `log()`, a redaction that threw, or a timed-out `flush()`. Default: one stderr line. The handler may be async; a rejection is swallowed.
|
|
23
|
-
- `maskEmail(address)` and `maskEmailsInText(text)`: mask email addresses (`m***@example.com`) inside message strings and cache keys, which key-based redaction cannot reach. Core's mail logs and the cache drivers' key logs use them
|
|
49
|
+
- `maskEmail(address)` and `maskEmailsInText(text)`: mask email addresses (`m***@example.com`) inside message strings and cache keys, which key-based redaction cannot reach. Core's mail logs and the cache drivers' key logs use them.
|
|
24
50
|
|
|
25
51
|
### Fixed
|
|
26
52
|
|
|
@@ -100,6 +126,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
|
|
|
100
126
|
### Changed
|
|
101
127
|
|
|
102
128
|
- Lockstep release maintenance and dependency refresh.
|
|
129
|
+
|
|
103
130
|
## 5.20.0 - 2026-09-24
|
|
104
131
|
|
|
105
132
|
### Changed
|
|
@@ -189,7 +216,7 @@ changelogs.
|
|
|
189
216
|
|
|
190
217
|
### Security
|
|
191
218
|
|
|
192
|
-
- **Secrets are now redacted by default. This is a behavior change — logs that previously showed these values in cleartext will now show `[REDACTED]`.** Redaction used to be a
|
|
219
|
+
- **Secrets are now redacted by default. This is a behavior change — logs that previously showed these values in cleartext will now show `[REDACTED]`.** Redaction used to be a _tool_ (`redact.paths`, entirely opt-in): unless an application configured it, a `password` in `context`, an `authorization` header, or an `apiKey` on a logged `Error` reached every sink — console, log file, JSON log file, Sentry — verbatim. Protection existed only where every call site had been configured correctly, with no signal when one hadn't. It is now a _default_.
|
|
193
220
|
|
|
194
221
|
A built-in denylist (`DEFAULT_REDACT_KEYS`) censors matching keys at any depth of `context`, `message`, and an `Error`'s own enumerable properties, applied at the same logger-wide choke point as `redact.paths` — so every channel inherits it, including custom ones. The set covers passwords, shared secrets, tokens (access/refresh/id/CSRF/session), API and private keys, HTTP credential headers (`authorization`, `x-api-key`, `cookie`, `set-cookie`), session IDs, connection strings, and high-sensitivity financial PII (card numbers, CVV, SSN, IBAN).
|
|
195
222
|
|
|
@@ -204,7 +231,7 @@ changelogs.
|
|
|
204
231
|
|
|
205
232
|
Paths are evaluated before keys, so a function `censor` on an explicit path still receives the original value rather than a mask, and that leaf is not censored twice.
|
|
206
233
|
|
|
207
|
-
Known residual gaps, unchanged by this release and documented on `applyRedact`: secrets interpolated into a `message`
|
|
234
|
+
Known residual gaps, unchanged by this release and documented on `applyRedact`: secrets interpolated into a `message` _string_ (`` `token=${t}` ``) cannot be reached by either matcher; `Map` / `Set` / `Buffer` contents are not traversed; and properties exposed only via getters or non-enumerable descriptors are not walked, so an HTTP client that hides its request config behind a getter can still slip through. Enumerable ones — axios's `.config` / `.response`, which carry the outgoing `Authorization` header — _are_ now covered.
|
|
208
235
|
|
|
209
236
|
### Fixed
|
|
210
237
|
|
package/README.md
CHANGED
|
@@ -23,10 +23,7 @@ yarn add @warlock.js/logger
|
|
|
23
23
|
```ts
|
|
24
24
|
import { log, ConsoleLog, FileLog } from "@warlock.js/logger";
|
|
25
25
|
|
|
26
|
-
log.setChannels([
|
|
27
|
-
new ConsoleLog(),
|
|
28
|
-
new FileLog({ chunk: "daily" }),
|
|
29
|
-
]);
|
|
26
|
+
log.setChannels([new ConsoleLog(), new FileLog({ chunk: "daily" })]);
|
|
30
27
|
|
|
31
28
|
log.info("users", "register", "New user created");
|
|
32
29
|
log.error("payments", "charge", new Error("Card declined"));
|
|
@@ -61,12 +58,12 @@ log.error({
|
|
|
61
58
|
|
|
62
59
|
## Built-in channels
|
|
63
60
|
|
|
64
|
-
| Channel
|
|
65
|
-
|
|
66
|
-
| `ConsoleLog`
|
|
67
|
-
| `FileLog`
|
|
68
|
-
| `JSONFileLog` | `"fileJson"` | Structured JSON files — ideal for aggregators
|
|
69
|
-
| `SentryLog`
|
|
61
|
+
| Channel | Name | Purpose |
|
|
62
|
+
| ------------- | ------------ | --------------------------------------------------------------------------------- |
|
|
63
|
+
| `ConsoleLog` | `"console"` | Colorized terminal output |
|
|
64
|
+
| `FileLog` | `"file"` | Plain-text files, optional chunking + rotation + grouping |
|
|
65
|
+
| `JSONFileLog` | `"fileJson"` | Structured JSON files — ideal for aggregators |
|
|
66
|
+
| `SentryLog` | `"sentry"` | Forwards to Sentry (events + breadcrumbs); needs the optional `@sentry/node` peer |
|
|
70
67
|
|
|
71
68
|
All channels share the `BasicLogConfigurations` options (`levels`, `filter`, `dateFormat`); `FileLog` / `JSONFileLog` add storage, chunking, rotation, and grouping options, and `SentryLog` adds `client` / `options` / `eventLevels`.
|
|
72
69
|
|
|
@@ -74,7 +71,7 @@ All channels share the `BasicLogConfigurations` options (`levels`, `filter`, `da
|
|
|
74
71
|
|
|
75
72
|
The package exports one default singleton and one class:
|
|
76
73
|
|
|
77
|
-
- **`log`** — a pre-instantiated `Logger`. Day-to-day logging
|
|
74
|
+
- **`log`** — a pre-instantiated `Logger`. Day-to-day logging _and_ configuration both go through it: `log.info(...)`, `log.configure(...)`, `log.flush()` / `log.flushSync()`, `log.addChannel(...)`.
|
|
78
75
|
- **`Logger`** — the class. Use it when you need an isolated logger (libraries, sandboxes, parallel test suites).
|
|
79
76
|
|
|
80
77
|
`log` is a `Logger` instance, not a function — every level shortcut and configuration method is reachable on it. The bare-callable `log(data)` form was removed; use `log.log(data)` for the data-object form, or `log.info(...)` / `log.error(...)` / etc. for the positional form.
|