@warlock.js/logger 4.8.1 → 4.9.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/cjs/index.cjs +10 -10
- package/cjs/index.cjs.map +1 -1
- package/esm/channels/console-log.d.mts +1 -1
- package/esm/channels/console-log.d.mts.map +1 -1
- package/esm/channels/console-log.mjs +1 -1
- package/esm/channels/console-log.mjs.map +1 -1
- package/esm/channels/file-log.d.mts +1 -1
- package/esm/channels/file-log.d.mts.map +1 -1
- package/esm/channels/file-log.mjs +1 -1
- package/esm/channels/file-log.mjs.map +1 -1
- package/esm/channels/json-file-log.d.mts +1 -1
- package/esm/channels/json-file-log.d.mts.map +1 -1
- package/esm/channels/json-file-log.mjs +1 -1
- package/esm/channels/json-file-log.mjs.map +1 -1
- package/esm/channels/sentry-log.d.mts +1 -1
- package/esm/channels/sentry-log.d.mts.map +1 -1
- package/esm/channels/sentry-log.mjs +1 -1
- package/esm/channels/sentry-log.mjs.map +1 -1
- package/esm/log-channel.d.mts +1 -1
- package/esm/log-channel.d.mts.map +1 -1
- package/esm/log-channel.mjs +1 -1
- package/esm/log-channel.mjs.map +1 -1
- package/esm/logger.d.mts +1 -1
- package/esm/logger.d.mts.map +1 -1
- package/esm/logger.mjs +1 -1
- package/esm/logger.mjs.map +1 -1
- package/esm/redact/redact.d.mts +1 -1
- package/esm/redact/redact.d.mts.map +1 -1
- package/esm/redact/redact.mjs +1 -1
- package/esm/redact/redact.mjs.map +1 -1
- package/esm/types.d.mts +1 -1
- package/esm/types.d.mts.map +1 -1
- package/esm/utils/capture-unhandled-errors.d.mts +1 -1
- package/esm/utils/capture-unhandled-errors.d.mts.map +1 -1
- package/esm/utils/capture-unhandled-errors.mjs +1 -1
- package/esm/utils/capture-unhandled-errors.mjs.map +1 -1
- package/esm/utils/clear-message.d.mts +1 -1
- package/esm/utils/clear-message.d.mts.map +1 -1
- package/esm/utils/clear-message.mjs +1 -1
- package/esm/utils/clear-message.mjs.map +1 -1
- package/esm/utils/safe-json-stringify.d.mts +1 -1
- package/esm/utils/safe-json-stringify.d.mts.map +1 -1
- package/esm/utils/safe-json-stringify.mjs +1 -1
- package/esm/utils/safe-json-stringify.mjs.map +1 -1
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"capture-unhandled-errors.mjs","names":[],"sources":["
|
|
1
|
+
{"version":3,"file":"capture-unhandled-errors.mjs","names":[],"sources":["../../../../../../../logger/src/utils/capture-unhandled-errors.ts"],"sourcesContent":["import { log } from \"../logger\";\r\n\r\n/**\r\n * Options for {@link captureAnyUnhandledRejection}.\r\n */\r\nexport type CaptureUnhandledOptions = {\r\n /**\r\n * Take the process down with `process.exit(1)` after an `uncaughtException`\r\n * is logged. Defaults to `true` — an uncaught exception leaves the process\r\n * in an undefined state, so Node's own default is to exit non-zero.\r\n *\r\n * Registering an `uncaughtException` listener *suppresses* that default, so a\r\n * listener that only logs turns an unrecoverable crash into a silent\r\n * `exit 0` (which is how a config file throwing at boot looks like \"the\r\n * server just stopped\"). Keep this `true` in production so supervisors\r\n * restart and the failure is never silent. Set it to `false` where the\r\n * process is expected to recover on its own — e.g. a dev server that reloads\r\n * via HMR — to log the exception without exiting.\r\n */\r\n exitOnUncaughtException?: boolean;\r\n};\r\n\r\n/**\r\n * Best-effort budget (ms) for draining async channels (file, Sentry, …) before\r\n * the forced exit. Bounded so a single stuck channel can't hang the process —\r\n * `process.exit()` skips `beforeExit`, so an `autoFlushOn: [\"beforeExit\"]`\r\n * handler would not cover this path.\r\n */\r\nconst FLUSH_BUDGET_BEFORE_EXIT = 1000;\r\n\r\n/**\r\n * Route Node's process-level failure events through the logger so they land in\r\n * every configured channel with full stack context, and make an\r\n * `uncaughtException` loud + visible instead of silently swallowed.\r\n *\r\n * Registers one listener for `unhandledRejection` and one for\r\n * `uncaughtException`; call once at startup after channels are configured.\r\n *\r\n * - `uncaughtException` → `log.fatal`, then (by default) `process.exit(1)`.\r\n * When no terminal channel has been configured yet — the early-boot window a\r\n * config file throwing at import time falls into — the stack is also written\r\n * to `console.error`, standing in for the Node default this listener\r\n * suppresses, so a fatal boot error is never invisible. A configured\r\n * `ConsoleLog` already prints it, so the fallback is skipped when a terminal\r\n * channel exists (no double output).\r\n * - `unhandledRejection` → `log.error` — a rejected promise is a failure but\r\n * not necessarily process-ending, so it stays at error and never exits.\r\n *\r\n * @example\r\n * log.configure({ channels: [new ConsoleLog(), new FileLog()] });\r\n * captureAnyUnhandledRejection(); // exits on uncaught\r\n * captureAnyUnhandledRejection({ exitOnUncaughtException: false }); // dev: log only\r\n */\r\nexport function captureAnyUnhandledRejection(options: CaptureUnhandledOptions = {}) {\r\n const { exitOnUncaughtException = true } = options;\r\n\r\n process.on(\"unhandledRejection\", (reason: any) => {\r\n log.error(\"app\", \"unhandledRejection\", reason);\r\n });\r\n\r\n process.on(\"uncaughtException\", (error) => {\r\n // Route through the logger first so file/Sentry channels capture it. A\r\n // crash handler must never itself throw (that would re-enter Node's\r\n // uncaught path), so the logging call is guarded.\r\n try {\r\n log.fatal(\"app\", \"uncaughtException\", error);\r\n } catch {\r\n // fall through to the stderr fallback + exit below\r\n }\r\n\r\n // Guarantee terminal visibility. `log.fatal` reaches nothing the user can\r\n // see when this fires before any terminal channel is configured — exactly\r\n // the early-boot window a config file throwing at import time falls into,\r\n // which is how a fatal boot error used to masquerade as a silent\r\n // `exit 0`. Stand in for the Node default this listener suppressed, but\r\n // only when no terminal channel already printed it, so a configured\r\n // `ConsoleLog` is never doubled.\r\n const hasTerminalChannel = log.channels.some((channel) => channel.terminal !== false);\r\n\r\n if (!hasTerminalChannel) {\r\n console.error(error);\r\n }\r\n\r\n if (!exitOnUncaughtException) {\r\n return;\r\n }\r\n\r\n // Best-effort, time-bounded flush of async channels, then exit non-zero so\r\n // process supervisors restart and `warlock start` surfaces the failure.\r\n void Promise.race([\r\n log.flush(),\r\n new Promise<void>((resolve) => {\r\n const timer = setTimeout(resolve, FLUSH_BUDGET_BEFORE_EXIT);\r\n timer.unref?.();\r\n }),\r\n ]).then(\r\n () => process.exit(1),\r\n () => process.exit(1),\r\n );\r\n });\r\n}\r\n"],"mappings":";;;;;;;;;AA4BA,MAAM,2BAA2B;;;;;;;;;;;;;;;;;;;;;;;;AAyBjC,SAAgB,6BAA6B,UAAmC,CAAC,GAAG;CAClF,MAAM,EAAE,0BAA0B,SAAS;CAE3C,QAAQ,GAAG,uBAAuB,WAAgB;EAChD,IAAI,MAAM,OAAO,sBAAsB,MAAM;CAC/C,CAAC;CAED,QAAQ,GAAG,sBAAsB,UAAU;EAIzC,IAAI;GACF,IAAI,MAAM,OAAO,qBAAqB,KAAK;EAC7C,QAAQ,CAER;EAWA,IAAI,CAFuB,IAAI,SAAS,MAAM,YAAY,QAAQ,aAAa,KAEzD,GACpB,QAAQ,MAAM,KAAK;EAGrB,IAAI,CAAC,yBACH;EAKF,AAAK,QAAQ,KAAK,CAChB,IAAI,MAAM,GACV,IAAI,SAAe,YAAY;GAE7B,AADc,WAAW,SAAS,wBAC9B,CAAC,CAAC,QAAQ;EAChB,CAAC,CACH,CAAC,CAAC,CAAC,WACK,QAAQ,KAAK,CAAC,SACd,QAAQ,KAAK,CAAC,CACtB;CACF,CAAC;AACH"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clear-message.d.mts","names":[],"sources":["
|
|
1
|
+
{"version":3,"file":"clear-message.d.mts","names":[],"sources":["../../../../../../../logger/src/utils/clear-message.ts"],"mappings":";;AAGA;;iBAAgB,YAAA,CAAa,OAAY"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clear-message.mjs","names":[],"sources":["
|
|
1
|
+
{"version":3,"file":"clear-message.mjs","names":[],"sources":["../../../../../../../logger/src/utils/clear-message.ts"],"sourcesContent":["/**\r\n * Clear message from any terminal codes\r\n */\r\nexport function clearMessage(message: any) {\r\n if (typeof message !== \"string\") return message;\r\n\r\n // eslint-disable-next-line no-control-regex\r\n return message.replace(/\\u001b[^m]*?m/g, \"\");\r\n}\r\n"],"mappings":";;;;AAGA,SAAgB,aAAa,SAAc;CACzC,IAAI,OAAO,YAAY,UAAU,OAAO;CAGxC,OAAO,QAAQ,QAAQ,kBAAkB,EAAE;AAC7C"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//#region
|
|
1
|
+
//#region ../logger/src/utils/safe-json-stringify.d.ts
|
|
2
2
|
/**
|
|
3
3
|
* JSON-serialize log payloads safely. Circular refs, BigInt, and repeated
|
|
4
4
|
* non-tree references are handled by `safe-stable-stringify`; functions and
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"safe-json-stringify.d.mts","names":[],"sources":["
|
|
1
|
+
{"version":3,"file":"safe-json-stringify.d.mts","names":[],"sources":["../../../../../../../logger/src/utils/safe-json-stringify.ts"],"mappings":";;AAyCA;;;;AAAgE;;;;iBAAhD,iBAAA,CAAkB,KAAA,WAAgB,KAAc"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { stringify } from "safe-stable-stringify";
|
|
2
2
|
|
|
3
|
-
//#region
|
|
3
|
+
//#region ../logger/src/utils/safe-json-stringify.ts
|
|
4
4
|
/**
|
|
5
5
|
* Replacer that surfaces Error data — `name`, `message`, and `stack` are
|
|
6
6
|
* non-enumerable on `Error`, so neither default JSON serialization nor an
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"safe-json-stringify.mjs","names":["safeStableStringify"],"sources":["
|
|
1
|
+
{"version":3,"file":"safe-json-stringify.mjs","names":["safeStableStringify"],"sources":["../../../../../../../logger/src/utils/safe-json-stringify.ts"],"sourcesContent":["import { stringify as safeStableStringify } from \"safe-stable-stringify\";\n\n/**\n * Replacer that surfaces Error data — `name`, `message`, and `stack` are\n * non-enumerable on `Error`, so neither default JSON serialization nor an\n * object spread captures them (both produce `{}`). They are copied explicitly;\n * the trailing spread then captures any additional enumerable props the caller\n * (or a subclass) attached, such as a `code` field.\n */\nfunction errorReplacer<Value = unknown>(\n _key: string,\n value: Value,\n): Record<string, unknown> | Value {\n if (value instanceof Error) {\n // Spread first, then the explicit Error fields. `name`/`message`/`stack`\n // are non-enumerable on `Error`, so the spread never carries them — the\n // explicit assignments are what surface them. Placing the spread first\n // means those explicit keys legitimately take precedence over any\n // identically-named *enumerable* prop a subclass attached (resolving the\n // duplicate-key warning). Because `safe-stable-stringify` sorts keys, the\n // insertion order here does not affect the serialized bytes.\n return {\n ...value,\n name: value.name,\n message: value.message,\n stack: value.stack,\n };\n }\n\n return value;\n}\n\n/**\n * JSON-serialize log payloads safely. Circular refs, BigInt, and repeated\n * non-tree references are handled by `safe-stable-stringify`; functions and\n * symbols are dropped (standard JSON behavior); Errors are expanded via\n * `errorReplacer`. Class instances serialize as their enumerable props.\n *\n * @example\n * await fs.promises.writeFile(filePath, safeJsonStringify(payload, 2));\n */\nexport function safeJsonStringify(value: unknown, space?: number): string {\n return safeStableStringify(value, errorReplacer, space) ?? \"\";\n}\n"],"mappings":";;;;;;;;;;AASA,SAAS,cACP,MACA,OACiC;CACjC,IAAI,iBAAiB,OAQnB,OAAO;EACL,GAAG;EACH,MAAM,MAAM;EACZ,SAAS,MAAM;EACf,OAAO,MAAM;CACf;CAGF,OAAO;AACT;;;;;;;;;;AAWA,SAAgB,kBAAkB,OAAgB,OAAwB;CACxE,OAAOA,UAAoB,OAAO,eAAe,KAAK,KAAK;AAC7D"}
|
package/package.json
CHANGED
|
@@ -17,14 +17,14 @@
|
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"@mongez/copper": "^2.1.2",
|
|
19
19
|
"@mongez/reinforcements": "^3.3.0",
|
|
20
|
-
"@warlock.js/fs": "4.
|
|
20
|
+
"@warlock.js/fs": "4.9.0",
|
|
21
21
|
"dayjs": "^1.11.9",
|
|
22
22
|
"safe-stable-stringify": "^2.5.0"
|
|
23
23
|
},
|
|
24
24
|
"peerDependencies": {
|
|
25
25
|
"@sentry/node": "^8.0.0 || ^9.0.0 || ^10.0.0"
|
|
26
26
|
},
|
|
27
|
-
"version": "4.
|
|
27
|
+
"version": "4.9.0",
|
|
28
28
|
"main": "./cjs/index.cjs",
|
|
29
29
|
"module": "./esm/index.mjs",
|
|
30
30
|
"types": "./esm/index.d.mts",
|