@gusto/baerly-storage 0.6.0 → 0.7.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/README.md +47 -124
- package/dist/API.md +161 -512
- package/dist/CHANGELOG.md +1137 -378
- package/dist/RECIPES.md +398 -80
- package/dist/THIRD-PARTY-LICENSES.txt +5 -26
- package/dist/{app-config-DyiFK3_k.d.ts → app-config-C6qW7m8S.d.ts} +119 -111
- package/dist/app-config.d.ts +31 -1
- package/dist/app-config.js +1 -2
- package/dist/app-config.js.map +1 -1
- package/dist/auth.d.ts +33 -28
- package/dist/auth.js +549 -985
- package/dist/auth.js.map +1 -1
- package/dist/baerly.js +130 -138
- package/dist/baerly.js.map +1 -1
- package/dist/baerly.spec.json +97 -22
- package/dist/capacity-warning-header-BlVopyiI.js +16 -0
- package/dist/capacity-warning-header-BlVopyiI.js.map +1 -0
- package/dist/{client-ypCm3zjt.d.ts → client-CHQTXpef.d.ts} +121 -36
- package/dist/client-react.d.ts +67 -20
- package/dist/client-react.js +240 -54
- package/dist/client-react.js.map +1 -1
- package/dist/client.d.ts +5 -4
- package/dist/client.js +51 -16
- package/dist/client.js.map +1 -1
- package/dist/{cloudflare-wrVYf4bb.js → cloudflare-CKHYXccw.js} +61 -82
- package/dist/cloudflare-CKHYXccw.js.map +1 -0
- package/dist/cloudflare.d.ts +106 -71
- package/dist/cloudflare.js +334 -271
- package/dist/cloudflare.js.map +1 -1
- package/dist/code-resolution-CL_7L0wS.js +22 -0
- package/dist/code-resolution-CL_7L0wS.js.map +1 -0
- package/dist/collection-api-DbyhLAY8.d.ts +1001 -0
- package/dist/config-DEzInG6M.js +4035 -0
- package/dist/config-DEzInG6M.js.map +1 -0
- package/dist/constants-D3GSH3tc.js +469 -0
- package/dist/constants-D3GSH3tc.js.map +1 -0
- package/dist/{context-DRZ3tZ5l.js → context-rlpSnHFA.js} +17 -17
- package/dist/context-rlpSnHFA.js.map +1 -0
- package/dist/cost-B52llVDx.js +330 -0
- package/dist/cost-B52llVDx.js.map +1 -0
- package/dist/{current-json-C6nhPOm1.js → current-json-CC6lE4Aj.js} +115 -32
- package/dist/current-json-CC6lE4Aj.js.map +1 -0
- package/dist/db-plFUNTSF.d.ts +130 -0
- package/dist/db-read-seams-BSs0m1z1.js +3261 -0
- package/dist/db-read-seams-BSs0m1z1.js.map +1 -0
- package/dist/{deploy-Di_Q01qx.js → deploy-Obj4nE-Z.js} +10 -14
- package/dist/deploy-Obj4nE-Z.js.map +1 -0
- package/dist/{dev-banner-CWHIk8tH.d.ts → dev-banner-B5AUHmu1.d.ts} +1 -4
- package/dist/dev-landing-BI5UdmOb.d.ts +32 -0
- package/dist/dev-landing-CD-si4dW.js +50 -0
- package/dist/dev-landing-CD-si4dW.js.map +1 -0
- package/dist/dev-vite.d.ts +9 -14
- package/dist/dev-vite.js +11 -10
- package/dist/dev-vite.js.map +1 -1
- package/dist/dev.d.ts +3 -2
- package/dist/dev.js +2 -1
- package/dist/doctor-BA0i-YAN.js +270 -0
- package/dist/doctor-BA0i-YAN.js.map +1 -0
- package/dist/dump-D1vX8ozg.js +133 -0
- package/dist/dump-D1vX8ozg.js.map +1 -0
- package/dist/errors-7Rk1HGCE.js +160 -0
- package/dist/errors-7Rk1HGCE.js.map +1 -0
- package/dist/{validate-DtljsCh1.js → export-BVL2EvYE.js} +409 -19
- package/dist/export-BVL2EvYE.js.map +1 -0
- package/dist/fsck-BWkPgov4.js +145 -0
- package/dist/fsck-BWkPgov4.js.map +1 -0
- package/dist/{gcs-admin-Bx6xSNJj.d.ts → gcs-admin-Dso1HWQj.d.ts} +18 -14
- package/dist/gcs.d.ts +19 -7
- package/dist/gcs.js +1 -2
- package/dist/{goog4-signer-Z7KnJ1su.js → goog4-signer-CeLIABoE.js} +102 -92
- package/dist/goog4-signer-CeLIABoE.js.map +1 -0
- package/dist/{http-7zT29K3P.js → http-Z5rZyYMX.js} +898 -271
- package/dist/http-Z5rZyYMX.js.map +1 -0
- package/dist/http-transport-DNUM8kU-.js +1299 -0
- package/dist/http-transport-DNUM8kU-.js.map +1 -0
- package/dist/http.d.ts +366 -294
- package/dist/http.js +2 -2
- package/dist/index-JJrIu1pO.d.ts +135 -0
- package/dist/index-LEgHN0qJ.d.ts +50 -0
- package/dist/{index-DP3ClvcA.d.ts → index-RiEYj8t0.d.ts} +291 -78
- package/dist/index.d.ts +27 -6
- package/dist/index.js +3 -5
- package/dist/inspect-BTsVYZKd.js +196 -0
- package/dist/inspect-BTsVYZKd.js.map +1 -0
- package/dist/{key-Di6yyxFu.js → key-C4FPZ9Io.js} +3 -4
- package/dist/{key-Di6yyxFu.js.map → key-C4FPZ9Io.js.map} +1 -1
- package/dist/ledger-Dj_bGgo0.js +192 -0
- package/dist/ledger-Dj_bGgo0.js.map +1 -0
- package/dist/legacy-names-DgZBtgOh.js +47 -0
- package/dist/legacy-names-DgZBtgOh.js.map +1 -0
- package/dist/log-C9W15Dfo.d.ts +94 -0
- package/dist/log-tail-DWJbneBF.js +142 -0
- package/dist/log-tail-DWJbneBF.js.map +1 -0
- package/dist/log-walk-C-vA-WGJ.js +111 -0
- package/dist/log-walk-C-vA-WGJ.js.map +1 -0
- package/dist/maintenance-Dd-Yakqj.js +1709 -0
- package/dist/maintenance-Dd-Yakqj.js.map +1 -0
- package/dist/maintenance-DevB6z4e.js +2237 -0
- package/dist/maintenance-DevB6z4e.js.map +1 -0
- package/dist/maintenance.d.ts +100 -3
- package/dist/maintenance.js +1 -3
- package/dist/node.d.ts +119 -92
- package/dist/node.js +3 -3
- package/dist/{observability-Ch-VQJyE.js → observability-C-ISCCLE.js} +1247 -326
- package/dist/observability-C-ISCCLE.js.map +1 -0
- package/dist/observability.d.ts +27 -3
- package/dist/observability.js +3 -3
- package/dist/path-segment-DBXG26PW.js +363 -0
- package/dist/path-segment-DBXG26PW.js.map +1 -0
- package/dist/{plan-C4qgiXSg.js → plan-BvQbaNMe.js} +19 -11
- package/dist/plan-BvQbaNMe.js.map +1 -0
- package/dist/request-CRWiTrza.js +272 -0
- package/dist/request-CRWiTrza.js.map +1 -0
- package/dist/restore-U6Im8V1V.js +1467 -0
- package/dist/restore-U6Im8V1V.js.map +1 -0
- package/dist/retry-OBtLB2GC.js +126 -0
- package/dist/retry-OBtLB2GC.js.map +1 -0
- package/dist/rolldown-runtime-D3KUYPsf.js +12 -0
- package/dist/{runtime-spec--LykAdl1.js → runtime-spec-B5mg3pHF.js} +189 -28
- package/dist/runtime-spec-B5mg3pHF.js.map +1 -0
- package/dist/{s3-http-DD5gDc7t.d.ts → s3-http-DBC_wiCL.d.ts} +14 -8
- package/dist/s3.d.ts +20 -7
- package/dist/s3.js +4 -5
- package/dist/s3.js.map +1 -1
- package/dist/{sha256-CqcKTjw9.js → sha256-4FfGQNPw.js} +9 -9
- package/dist/sha256-4FfGQNPw.js.map +1 -0
- package/dist/{shared-secret-DgEicd3x.js → shared-secret-Vkur-8r0.js} +27 -15
- package/dist/shared-secret-Vkur-8r0.js.map +1 -0
- package/dist/{aws4fetch.esm-CXE5ZbAa.js → sigv4-sign-5IUflUD_.js} +143 -96
- package/dist/sigv4-sign-5IUflUD_.js.map +1 -0
- package/dist/snapshot-CknzkDM0.js +148 -0
- package/dist/snapshot-CknzkDM0.js.map +1 -0
- package/dist/{src-BMFfDUI2.js → src-Actga-bO.js} +949 -363
- package/dist/src-Actga-bO.js.map +1 -0
- package/dist/src-D0MQfvOp.js +812 -0
- package/dist/src-D0MQfvOp.js.map +1 -0
- package/dist/src-Dr9uo3dc.js +501 -0
- package/dist/src-Dr9uo3dc.js.map +1 -0
- package/dist/{subcommand-BV68pqwJ.js → subcommand-BLoF66dG.js} +89 -16
- package/dist/subcommand-BLoF66dG.js.map +1 -0
- package/dist/{time-DUqvFMHq.js → time-DRxTP9iv.js} +15 -34
- package/dist/time-DRxTP9iv.js.map +1 -0
- package/dist/types-suVbsEWS.d.ts +116 -0
- package/dist/{usage-BMZR8o6U.js → usage-CPzVhrQr.js} +40 -45
- package/dist/usage-CPzVhrQr.js.map +1 -0
- package/dist/uuid-BuT_c404.js +333 -0
- package/dist/uuid-BuT_c404.js.map +1 -0
- package/dist/verifier-Bmlmndzo.d.ts +95 -0
- package/dist/{wire-izfGZDvr.js → wire-DndvKU-K.js} +2 -3
- package/dist/wire-DndvKU-K.js.map +1 -0
- package/package.json +90 -69
- package/dist/aws4fetch.esm-CXE5ZbAa.js.map +0 -1
- package/dist/bytes-BXdamO3L.js +0 -11
- package/dist/bytes-BXdamO3L.js.map +0 -1
- package/dist/cloudflare-wrVYf4bb.js.map +0 -1
- package/dist/config-B6nTy8e2.js +0 -3095
- package/dist/config-B6nTy8e2.js.map +0 -1
- package/dist/constants-CfeMWQWk.js +0 -222
- package/dist/constants-CfeMWQWk.js.map +0 -1
- package/dist/context-DRZ3tZ5l.js.map +0 -1
- package/dist/cost-_SE_SVgZ.js +0 -203
- package/dist/cost-_SE_SVgZ.js.map +0 -1
- package/dist/current-json-C6nhPOm1.js.map +0 -1
- package/dist/db-DjjthkTi.d.ts +0 -254
- package/dist/deploy-Di_Q01qx.js.map +0 -1
- package/dist/doctor-RWVRpvat.js +0 -102
- package/dist/doctor-RWVRpvat.js.map +0 -1
- package/dist/dump-m2vEYDNY.js +0 -94
- package/dist/dump-m2vEYDNY.js.map +0 -1
- package/dist/errors-Dfa3p78c.js +0 -78
- package/dist/errors-Dfa3p78c.js.map +0 -1
- package/dist/export-DenKwEQu.js +0 -401
- package/dist/export-DenKwEQu.js.map +0 -1
- package/dist/fsck-2Vq-7-e2.js +0 -279
- package/dist/fsck-2Vq-7-e2.js.map +0 -1
- package/dist/goog4-signer-Z7KnJ1su.js.map +0 -1
- package/dist/http-7zT29K3P.js.map +0 -1
- package/dist/http-transport-BTgVCY5r.js +0 -1250
- package/dist/http-transport-BTgVCY5r.js.map +0 -1
- package/dist/index-BHz92Acj.d.ts +0 -162
- package/dist/index-CEZKQsKt.d.ts +0 -1113
- package/dist/index-uE-w2dgj.d.ts +0 -115
- package/dist/indexes-Dn9hbGQG.d.ts +0 -22
- package/dist/inspect-BpYbH1DM.js +0 -133
- package/dist/inspect-BpYbH1DM.js.map +0 -1
- package/dist/log-tail-QWU4wlu-.js +0 -514
- package/dist/log-tail-QWU4wlu-.js.map +0 -1
- package/dist/maintenance-BGHGt2Yg.d.ts +0 -537
- package/dist/maintenance-DULFcpd1.js +0 -2144
- package/dist/maintenance-DULFcpd1.js.map +0 -1
- package/dist/maintenance-fEi-UZ2o.js +0 -1412
- package/dist/maintenance-fEi-UZ2o.js.map +0 -1
- package/dist/normalize-rjnZLwS4.js +0 -133
- package/dist/normalize-rjnZLwS4.js.map +0 -1
- package/dist/observability-Ch-VQJyE.js.map +0 -1
- package/dist/plan-C4qgiXSg.js.map +0 -1
- package/dist/query-C43r-6ib.js +0 -1773
- package/dist/query-C43r-6ib.js.map +0 -1
- package/dist/rebuild-index-BH1dc1p6.js +0 -81
- package/dist/rebuild-index-BH1dc1p6.js.map +0 -1
- package/dist/request-u0M51mhJ.js +0 -72
- package/dist/request-u0M51mhJ.js.map +0 -1
- package/dist/restore-D0VYWzfP.js +0 -778
- package/dist/restore-D0VYWzfP.js.map +0 -1
- package/dist/rolldown-runtime-EAsCxrDo.js +0 -14
- package/dist/runtime-spec--LykAdl1.js.map +0 -1
- package/dist/sha256-CqcKTjw9.js.map +0 -1
- package/dist/shared-secret-DgEicd3x.js.map +0 -1
- package/dist/src-BMFfDUI2.js.map +0 -1
- package/dist/src-DYZ4H1aF.js +0 -392
- package/dist/src-DYZ4H1aF.js.map +0 -1
- package/dist/src-DvbTEya2.js +0 -536
- package/dist/src-DvbTEya2.js.map +0 -1
- package/dist/subcommand-BV68pqwJ.js.map +0 -1
- package/dist/time-DUqvFMHq.js.map +0 -1
- package/dist/usage-BMZR8o6U.js.map +0 -1
- package/dist/validate-DtljsCh1.js.map +0 -1
- package/dist/wire-izfGZDvr.js.map +0 -1
|
@@ -1,73 +1,86 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { n as
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const CODE_RESOLUTIONS = {
|
|
7
|
-
PayloadTooLarge: "Reduce the request body below the server's body-size cap (1 MiB default).",
|
|
8
|
-
Unauthorized: "Send a valid Authorization header for the server's configured auth method.",
|
|
9
|
-
AccessDenied: "These credentials are denied for this tenant prefix or bucket policy.",
|
|
10
|
-
NotFound: "No row matches this id; create it first or treat this as a miss."
|
|
11
|
-
};
|
|
12
|
-
/** Resolution for a malformed `?where=` / `?order=` query value. */
|
|
13
|
-
const WHERE_ORDER_JSON_RESOLUTION = "Pass a URL-encoded JSON object as the ?where= / ?order= value.";
|
|
14
|
-
/** Resolution for an empty / malformed / unwrapped write body. */
|
|
15
|
-
const WRITE_BODY_SHAPE_RESOLUTION = "Send a JSON body shaped { \"doc\": { ... } } for POST/PUT, or { \"patch\": { ... } } for PATCH.";
|
|
16
|
-
//#endregion
|
|
17
|
-
//#region packages/server/src/contract.ts
|
|
1
|
+
import { t as __exportAll } from "./rolldown-runtime-D3KUYPsf.js";
|
|
2
|
+
import { i as runWithContext, n as ctxMetrics, r as getCurrentContext$1, t as createObservabilityContext$1 } from "./context-rlpSnHFA.js";
|
|
3
|
+
import { r as isRetriableCode, t as BaerlyError } from "./errors-7Rk1HGCE.js";
|
|
4
|
+
import { t as CODE_RESOLUTIONS } from "./code-resolution-CL_7L0wS.js";
|
|
5
|
+
// packages/server/src/contract.ts
|
|
18
6
|
/**
|
|
19
7
|
* Single drift surface for the {@link HttpErrorEnvelope} shape. The
|
|
20
8
|
* router and both adapters call this — adding or renaming a field on
|
|
21
|
-
* the wire is a one-edit change here. `retriable` is
|
|
22
|
-
*
|
|
9
|
+
* the wire is a one-edit change here. `retriable` is always present and
|
|
10
|
+
* derived from `code` alone; older clients ignore it.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* errorEnvelope("InvalidConfig", "bad request", { resolution: "Pass ?collection=<name>." });
|
|
15
|
+
* errorEnvelope("AmbiguousCommit", "unknown outcome", { _id: "t-1" });
|
|
16
|
+
* ```
|
|
23
17
|
*/
|
|
24
|
-
const errorEnvelope = (code, message,
|
|
18
|
+
const errorEnvelope = (code, message, options) => {
|
|
19
|
+
const { issues, resolution, _id, retryAfter } = options ?? {};
|
|
25
20
|
const resolved = resolution ?? CODE_RESOLUTIONS[code];
|
|
26
21
|
return { error: {
|
|
27
22
|
code,
|
|
28
23
|
message,
|
|
29
|
-
retriable:
|
|
24
|
+
retriable: isRetriableCode(code),
|
|
30
25
|
...issues !== void 0 && issues.length > 0 ? { issues } : {},
|
|
31
|
-
...resolved !== void 0 ? { resolution: resolved } : {}
|
|
26
|
+
...resolved !== void 0 ? { resolution: resolved } : {},
|
|
27
|
+
..._id !== void 0 && code === "AmbiguousCommit" ? { _id } : {},
|
|
28
|
+
...retryAfter !== void 0 && code === "MaintenancePending" ? { retryAfter } : {}
|
|
32
29
|
} };
|
|
33
30
|
};
|
|
34
|
-
|
|
35
|
-
|
|
31
|
+
// node_modules/.pnpm/@logtape+logtape@2.4.2/node_modules/@logtape/logtape/dist/disposable.js
|
|
32
|
+
const disposeSymbol = Symbol.dispose ?? Symbol.for("Symbol.dispose");
|
|
33
|
+
const asyncDisposeSymbol = Symbol.asyncDispose ?? Symbol.for("Symbol.asyncDispose");
|
|
34
|
+
// node_modules/.pnpm/@logtape+logtape@2.4.2/node_modules/@logtape/logtape/dist/filter.js
|
|
36
35
|
/**
|
|
37
|
-
*
|
|
36
|
+
* Converts a {@link FilterLike} value to an actual {@link Filter}.
|
|
37
|
+
*
|
|
38
|
+
* @param filter The filter-like value to convert.
|
|
39
|
+
* @returns The actual filter.
|
|
38
40
|
*/
|
|
39
|
-
|
|
41
|
+
function toFilter(filter) {
|
|
42
|
+
if (typeof filter === "function") return filter;
|
|
43
|
+
return getLevelFilter(filter);
|
|
44
|
+
}
|
|
40
45
|
/**
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
* @
|
|
46
|
+
* Returns a filter that accepts log records with the specified level.
|
|
47
|
+
*
|
|
48
|
+
* @param level The level to filter by. If `null`, the filter will reject all
|
|
49
|
+
* records.
|
|
50
|
+
* @returns The filter.
|
|
44
51
|
*/
|
|
45
|
-
function
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
return Array.isArray(prefix) ? prefix : [];
|
|
52
|
+
function getLevelFilter(level) {
|
|
53
|
+
const filter = createLevelFilter(level);
|
|
54
|
+
levelFilters.set(filter, level);
|
|
55
|
+
return filter;
|
|
50
56
|
}
|
|
51
57
|
/**
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
* active, while `getImplicitContext()` keeps its public return contract.
|
|
57
|
-
* @returns The current implicit context without internal symbol keys, or
|
|
58
|
-
* `undefined` if there is no user-visible implicit context.
|
|
58
|
+
* The levels of the filters made by {@link getLevelFilter}, so that they can
|
|
59
|
+
* be described without being invoked. It is shared through `globalThis` like
|
|
60
|
+
* the root logger, so that filters made by another copy of LogTape in the same
|
|
61
|
+
* process (e.g., the CommonJS build next to the ESM build) are recognized too.
|
|
59
62
|
*/
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
63
|
+
const levelFilters = getLevelFilters();
|
|
64
|
+
function getLevelFilters() {
|
|
65
|
+
const registry = globalThis;
|
|
66
|
+
const key = Symbol.for("logtape.levelFilters");
|
|
67
|
+
const map = registry[key];
|
|
68
|
+
if (map instanceof WeakMap) return map;
|
|
69
|
+
const newMap = /* @__PURE__ */ new WeakMap();
|
|
70
|
+
registry[key] = newMap;
|
|
71
|
+
return newMap;
|
|
72
|
+
}
|
|
73
|
+
function createLevelFilter(level) {
|
|
74
|
+
if (level == null) return () => false;
|
|
75
|
+
if (level === "fatal") return (record) => record.level === "fatal";
|
|
76
|
+
else if (level === "error") return (record) => record.level === "fatal" || record.level === "error";
|
|
77
|
+
else if (level === "warning") return (record) => record.level === "fatal" || record.level === "error" || record.level === "warning";
|
|
78
|
+
else if (level === "info") return (record) => record.level === "fatal" || record.level === "error" || record.level === "warning" || record.level === "info";
|
|
79
|
+
else if (level === "debug") return (record) => record.level === "fatal" || record.level === "error" || record.level === "warning" || record.level === "info" || record.level === "debug";
|
|
80
|
+
else if (level === "trace") return () => true;
|
|
81
|
+
throw new TypeError(`Invalid log level: ${level}.`);
|
|
68
82
|
}
|
|
69
|
-
|
|
70
|
-
//#region node_modules/.pnpm/@logtape+logtape@2.2.4/node_modules/@logtape/logtape/dist/level.js
|
|
83
|
+
// node_modules/.pnpm/@logtape+logtape@2.4.2/node_modules/@logtape/logtape/dist/level.js
|
|
71
84
|
const logLevels = [
|
|
72
85
|
"trace",
|
|
73
86
|
"debug",
|
|
@@ -91,8 +104,230 @@ function compareLogLevel(a, b) {
|
|
|
91
104
|
if (bIndex < 0) throw new TypeError(`Invalid log level: ${JSON.stringify(b)}.`);
|
|
92
105
|
return aIndex - bIndex;
|
|
93
106
|
}
|
|
94
|
-
|
|
95
|
-
|
|
107
|
+
// node_modules/.pnpm/@logtape+logtape@2.4.2/node_modules/@logtape/logtape/dist/scoped-config.js
|
|
108
|
+
const scopedConfigSymbol = Symbol.for("logtape.scopedConfig");
|
|
109
|
+
const defaultScopedLogger = {
|
|
110
|
+
filters: [],
|
|
111
|
+
filterIds: [],
|
|
112
|
+
lowestLevel: "trace",
|
|
113
|
+
parentSinks: "inherit",
|
|
114
|
+
sinks: [],
|
|
115
|
+
sinkIds: [],
|
|
116
|
+
captureSourceLocation: void 0
|
|
117
|
+
};
|
|
118
|
+
const noFilters = [];
|
|
119
|
+
function getCurrentScopedConfig(contextLocalStorage) {
|
|
120
|
+
const scopedConfig = (contextLocalStorage?.getStore())?.[scopedConfigSymbol];
|
|
121
|
+
return isCompiledScopedConfig(scopedConfig) ? getActiveScopedConfig(scopedConfig) : void 0;
|
|
122
|
+
}
|
|
123
|
+
function scopedConfigHasSink(scopedConfig, category, level) {
|
|
124
|
+
return getScopedSinkDispatchPlan(scopedConfig, category, level).kind !== "none";
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Resolves whether source locations are captured for the given category
|
|
128
|
+
* under the scoped configuration: the setting of the nearest configured
|
|
129
|
+
* category, from the category itself up to the root, wins.
|
|
130
|
+
*/
|
|
131
|
+
function scopedConfigCapturesSourceLocation(scopedConfig, category) {
|
|
132
|
+
if (!scopedConfig.capturesSourceLocation) return false;
|
|
133
|
+
const key = categoryKey(category);
|
|
134
|
+
let captures = scopedConfig.sourceLocationCaptureCache.get(key);
|
|
135
|
+
if (captures == null) {
|
|
136
|
+
captures = false;
|
|
137
|
+
for (let length = category.length; length >= 0; length--) {
|
|
138
|
+
const logger = scopedConfig.nodes.get(categoryKey(category.slice(0, length)));
|
|
139
|
+
if (logger?.captureSourceLocation == null) continue;
|
|
140
|
+
captures = logger.captureSourceLocation;
|
|
141
|
+
break;
|
|
142
|
+
}
|
|
143
|
+
scopedConfig.sourceLocationCaptureCache.set(key, captures);
|
|
144
|
+
}
|
|
145
|
+
return captures;
|
|
146
|
+
}
|
|
147
|
+
function emitWithScopedConfig(scopedConfig, record, bypassSinks, emitToSink) {
|
|
148
|
+
const plan = getScopedSinkDispatchPlan(scopedConfig, record.category, record.level);
|
|
149
|
+
if (plan.kind === "none") return;
|
|
150
|
+
if (!filterScopedRecord(scopedConfig, record.category, record)) return;
|
|
151
|
+
if (plan.kind === "one") {
|
|
152
|
+
if (!bypassSinks?.has(plan.sink)) emitToSink(plan.sink, bypassSinks);
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
for (const sink of plan.sinks) {
|
|
156
|
+
if (bypassSinks?.has(sink)) continue;
|
|
157
|
+
emitToSink(sink, bypassSinks);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
function isCompiledScopedConfig(value) {
|
|
161
|
+
return value != null && typeof value === "object" && "nodes" in value;
|
|
162
|
+
}
|
|
163
|
+
function getActiveScopedConfig(scopedConfig) {
|
|
164
|
+
let activeConfig = scopedConfig;
|
|
165
|
+
while (activeConfig?.disposed) activeConfig = activeConfig.parent;
|
|
166
|
+
return activeConfig;
|
|
167
|
+
}
|
|
168
|
+
function categoryKey(category) {
|
|
169
|
+
return JSON.stringify(category);
|
|
170
|
+
}
|
|
171
|
+
function getScopedSinkDispatchPlan(scopedConfig, category, level) {
|
|
172
|
+
const cacheKey = `${categoryKey(category)}:${level}`;
|
|
173
|
+
let plan = scopedConfig.dispatchCache.get(cacheKey);
|
|
174
|
+
if (plan == null) {
|
|
175
|
+
plan = getScopedSinkDispatchPlanForPrefix(scopedConfig, category, category.length, level);
|
|
176
|
+
scopedConfig.dispatchCache.set(cacheKey, plan);
|
|
177
|
+
}
|
|
178
|
+
return plan;
|
|
179
|
+
}
|
|
180
|
+
function getScopedSinkDispatchPlanForPrefix(scopedConfig, category, length, level) {
|
|
181
|
+
const prefix = category.slice(0, length);
|
|
182
|
+
const logger = scopedConfig.nodes.get(categoryKey(prefix)) ?? defaultScopedLogger;
|
|
183
|
+
if (logger.lowestLevel === null || compareLogLevel(level, logger.lowestLevel) < 0) return { kind: "none" };
|
|
184
|
+
const parentPlan = length > 0 && logger.parentSinks === "inherit" ? getScopedSinkDispatchPlanForPrefix(scopedConfig, category, length - 1, level) : length > 0 && logger.parentSinks === "forward" ? wrapScopedSinks(collectScopedForwardSinks(scopedConfig, category, length - 1)) : { kind: "none" };
|
|
185
|
+
let firstSink;
|
|
186
|
+
let sinks;
|
|
187
|
+
const appendSink = (sink) => {
|
|
188
|
+
if (sinks != null) sinks.push(sink);
|
|
189
|
+
else if (firstSink == null) firstSink = sink;
|
|
190
|
+
else sinks = [firstSink, sink];
|
|
191
|
+
};
|
|
192
|
+
if (parentPlan.kind === "one") appendSink(parentPlan.sink);
|
|
193
|
+
else if (parentPlan.kind === "many") for (const sink of parentPlan.sinks) appendSink(sink);
|
|
194
|
+
for (const sink of logger.sinks) appendSink(sink);
|
|
195
|
+
if (sinks != null) return {
|
|
196
|
+
kind: "many",
|
|
197
|
+
sinks
|
|
198
|
+
};
|
|
199
|
+
if (firstSink != null) return {
|
|
200
|
+
kind: "one",
|
|
201
|
+
sink: firstSink
|
|
202
|
+
};
|
|
203
|
+
return { kind: "none" };
|
|
204
|
+
}
|
|
205
|
+
function collectScopedForwardSinks(scopedConfig, category, length) {
|
|
206
|
+
const logger = scopedConfig.nodes.get(categoryKey(category.slice(0, length))) ?? defaultScopedLogger;
|
|
207
|
+
const parentSinks = length > 0 && logger.parentSinks !== "override" ? collectScopedForwardSinks(scopedConfig, category, length - 1) : [];
|
|
208
|
+
if (logger.sinks.length < 1) return parentSinks;
|
|
209
|
+
if (parentSinks.length < 1) return logger.sinks;
|
|
210
|
+
return [...parentSinks, ...logger.sinks];
|
|
211
|
+
}
|
|
212
|
+
function wrapScopedSinks(sinks) {
|
|
213
|
+
if (sinks.length < 1) return { kind: "none" };
|
|
214
|
+
if (sinks.length === 1) return {
|
|
215
|
+
kind: "one",
|
|
216
|
+
sink: sinks[0]
|
|
217
|
+
};
|
|
218
|
+
return {
|
|
219
|
+
kind: "many",
|
|
220
|
+
sinks
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
function filterScopedRecord(scopedConfig, category, record) {
|
|
224
|
+
const key = categoryKey(category);
|
|
225
|
+
let filters = scopedConfig.filterCache.get(key);
|
|
226
|
+
if (filters == null) {
|
|
227
|
+
filters = getScopedFilters(scopedConfig, category);
|
|
228
|
+
scopedConfig.filterCache.set(key, filters);
|
|
229
|
+
}
|
|
230
|
+
return filters.every((filter) => filter(record));
|
|
231
|
+
}
|
|
232
|
+
function getScopedFilters(scopedConfig, category) {
|
|
233
|
+
for (let length = category.length; length >= 0; length--) {
|
|
234
|
+
const logger = scopedConfig.nodes.get(categoryKey(category.slice(0, length)));
|
|
235
|
+
if (logger == null || logger.filters.length < 1) continue;
|
|
236
|
+
return logger.filters;
|
|
237
|
+
}
|
|
238
|
+
return noFilters;
|
|
239
|
+
}
|
|
240
|
+
// node_modules/.pnpm/@logtape+logtape@2.4.2/node_modules/@logtape/logtape/dist/source-location.js
|
|
241
|
+
/**
|
|
242
|
+
* The prefix of each frame in V8 and JavaScriptCore (Bun) stack traces.
|
|
243
|
+
*/
|
|
244
|
+
const v8FramePrefix = " at ";
|
|
245
|
+
/**
|
|
246
|
+
* Matches a file that starts with a URL scheme (e.g., `file:`, `http:`,
|
|
247
|
+
* `node:`, or a Windows drive letter), a slash, or a UNC prefix.
|
|
248
|
+
*/
|
|
249
|
+
const absoluteFilePattern = /^(?:[A-Za-z][A-Za-z0-9+.-]*:|\/|\\\\)/;
|
|
250
|
+
/**
|
|
251
|
+
* Matches a `file:line:column` location.
|
|
252
|
+
*/
|
|
253
|
+
const locationPattern = /^(.+):(\d+):(\d+)$/;
|
|
254
|
+
/**
|
|
255
|
+
* Marks a location that matched the grammar but must not be reported.
|
|
256
|
+
*/
|
|
257
|
+
const rejected = Symbol("rejected");
|
|
258
|
+
/**
|
|
259
|
+
* Parses the source location of a frame from the stack trace of an `Error`
|
|
260
|
+
* that was constructed without a message.
|
|
261
|
+
*
|
|
262
|
+
* The parser is deliberately conservative: whenever the frame could be read
|
|
263
|
+
* in more than one way, or it does not point to a position in a source file
|
|
264
|
+
* (native code, `eval()`, bytecode offsets), it returns `undefined` rather
|
|
265
|
+
* than a possibly wrong location. It never throws.
|
|
266
|
+
*
|
|
267
|
+
* @param stack The `stack` property of an `Error` constructed without
|
|
268
|
+
* a message.
|
|
269
|
+
* @param frameIndex The zero-based index of the frame to parse, where `0`
|
|
270
|
+
* is the function that constructed the `Error`.
|
|
271
|
+
* @returns The source location of the frame, or `undefined` if it could not
|
|
272
|
+
* be determined unambiguously.
|
|
273
|
+
*/
|
|
274
|
+
function parseSourceLocation(stack, frameIndex) {
|
|
275
|
+
if (typeof stack !== "string") return void 0;
|
|
276
|
+
const lines = stack.split("\n");
|
|
277
|
+
if (lines[0].trim() === "Error") {
|
|
278
|
+
if (lines.length < 2 || !lines[1].startsWith(v8FramePrefix)) return void 0;
|
|
279
|
+
return parseV8Frame(lines[frameIndex + 1]);
|
|
280
|
+
}
|
|
281
|
+
if (lines[0] === "" || /^\s/.test(lines[0])) return void 0;
|
|
282
|
+
return parseSpiderMonkeyFrame(lines[frameIndex]);
|
|
283
|
+
}
|
|
284
|
+
function parseV8Frame(frame) {
|
|
285
|
+
if (frame == null || !frame.startsWith(v8FramePrefix)) return void 0;
|
|
286
|
+
const body = frame.slice(7);
|
|
287
|
+
if (body.includes("eval at ")) return void 0;
|
|
288
|
+
if (!body.endsWith(")")) return accept(parseLocation(body.startsWith("async ") ? body.slice(6) : body));
|
|
289
|
+
let found;
|
|
290
|
+
for (let i = body.indexOf(" ("); i >= 0; i = body.indexOf(" (", i + 1)) {
|
|
291
|
+
const location = parseLocation(body.slice(i + 2, -1));
|
|
292
|
+
if (location === rejected) return void 0;
|
|
293
|
+
if (location == null) continue;
|
|
294
|
+
if (found != null) return void 0;
|
|
295
|
+
found = location;
|
|
296
|
+
}
|
|
297
|
+
return found;
|
|
298
|
+
}
|
|
299
|
+
function parseSpiderMonkeyFrame(frame) {
|
|
300
|
+
if (frame == null) return void 0;
|
|
301
|
+
const whole = parseLocation(frame);
|
|
302
|
+
if (whole === rejected) return void 0;
|
|
303
|
+
if (whole != null && absoluteFilePattern.test(whole.file)) return void 0;
|
|
304
|
+
let found;
|
|
305
|
+
for (let i = frame.indexOf("@"); i >= 0; i = frame.indexOf("@", i + 1)) {
|
|
306
|
+
const location = parseLocation(frame.slice(i + 1));
|
|
307
|
+
if (location === rejected) return void 0;
|
|
308
|
+
if (location == null || !absoluteFilePattern.test(location.file)) continue;
|
|
309
|
+
if (found != null) return void 0;
|
|
310
|
+
found = location;
|
|
311
|
+
}
|
|
312
|
+
return found;
|
|
313
|
+
}
|
|
314
|
+
function accept(location) {
|
|
315
|
+
return location === rejected ? void 0 : location;
|
|
316
|
+
}
|
|
317
|
+
function parseLocation(location) {
|
|
318
|
+
const match = locationPattern.exec(location);
|
|
319
|
+
if (match == null) return void 0;
|
|
320
|
+
const file = match[1];
|
|
321
|
+
const line = Number(match[2]);
|
|
322
|
+
const column = Number(match[3]);
|
|
323
|
+
if (file === "native" || file === "<anonymous>" || file === "[native code]" || file.includes("address at ") || file.includes("eval at ") || file.includes(" > eval") || file.includes(" > Function") || line < 1 || column < 1) return rejected;
|
|
324
|
+
return {
|
|
325
|
+
file,
|
|
326
|
+
line,
|
|
327
|
+
column
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
// node_modules/.pnpm/@logtape+logtape@2.4.2/node_modules/@logtape/logtape/dist/logger.js
|
|
96
331
|
/**
|
|
97
332
|
* Symbol to identify lazy values.
|
|
98
333
|
*/
|
|
@@ -101,6 +336,15 @@ const throttlingSummaryRecordSymbol = Symbol.for("LogTape.throttlingSummaryRecor
|
|
|
101
336
|
const immediateSinkSymbol = Symbol.for("LogTape.sinkSnapshotPolicy.immediate");
|
|
102
337
|
const internalStringLogRecords = /* @__PURE__ */ new WeakSet();
|
|
103
338
|
const resolvedStringLogRecords = /* @__PURE__ */ new WeakSet();
|
|
339
|
+
let globalSourceLocationCapture = false;
|
|
340
|
+
let scopedSourceLocationCaptures = 0;
|
|
341
|
+
function isSourceLocationCaptureActive() {
|
|
342
|
+
return globalSourceLocationCapture || scopedSourceLocationCaptures > 0;
|
|
343
|
+
}
|
|
344
|
+
function attachSourceLocation(record, sourceLocation) {
|
|
345
|
+
if (sourceLocation == null) return;
|
|
346
|
+
record.sourceLocation = sourceLocation;
|
|
347
|
+
}
|
|
104
348
|
/**
|
|
105
349
|
* Checks if a value is a lazy value.
|
|
106
350
|
*
|
|
@@ -135,32 +379,36 @@ function isPromiseObject(value) {
|
|
|
135
379
|
if (value instanceof Promise) return true;
|
|
136
380
|
return Object.prototype.toString.call(value) === "[object Promise]" && typeof value.then === "function";
|
|
137
381
|
}
|
|
138
|
-
function logStringMessage(logger, level, message, props) {
|
|
382
|
+
function logStringMessage(logger, level, message, props, sourceLocation) {
|
|
139
383
|
if (typeof props !== "function") {
|
|
140
384
|
const properties = props ?? {};
|
|
141
|
-
logger.log(level, message, properties);
|
|
385
|
+
logger.log(level, message, properties, void 0, sourceLocation);
|
|
142
386
|
return;
|
|
143
387
|
}
|
|
144
388
|
if (!logger.isEnabledFor(level)) return Promise.resolve();
|
|
145
389
|
const result = props();
|
|
146
390
|
if (isPromiseObject(result)) return Promise.resolve(result).then((resolvedProps) => {
|
|
147
|
-
logger.log(level, message, resolvedProps);
|
|
391
|
+
logger.log(level, message, resolvedProps, void 0, sourceLocation);
|
|
148
392
|
});
|
|
149
|
-
logger.log(level, message, result);
|
|
393
|
+
logger.log(level, message, result, void 0, sourceLocation);
|
|
150
394
|
}
|
|
151
395
|
function snapshotLogRecordProperties(record) {
|
|
152
396
|
if (resolvedStringLogRecords.has(record)) return record;
|
|
153
397
|
const properties = resolveProperties(record.properties);
|
|
154
|
-
if (internalStringLogRecords.has(record))
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
398
|
+
if (internalStringLogRecords.has(record)) {
|
|
399
|
+
const snapshot = {
|
|
400
|
+
category: record.category,
|
|
401
|
+
level: record.level,
|
|
402
|
+
get message() {
|
|
403
|
+
return record.message;
|
|
404
|
+
},
|
|
405
|
+
rawMessage: record.rawMessage,
|
|
406
|
+
timestamp: record.timestamp,
|
|
407
|
+
properties
|
|
408
|
+
};
|
|
409
|
+
attachSourceLocation(snapshot, record.sourceLocation);
|
|
410
|
+
return snapshot;
|
|
411
|
+
}
|
|
164
412
|
const descriptors = Object.getOwnPropertyDescriptors(record);
|
|
165
413
|
descriptors.properties = {
|
|
166
414
|
value: properties,
|
|
@@ -195,6 +443,10 @@ function getLogger$1(category = []) {
|
|
|
195
443
|
* The symbol for the global root logger.
|
|
196
444
|
*/
|
|
197
445
|
const globalRootLoggerSymbol = Symbol.for("logtape.rootLogger");
|
|
446
|
+
/**
|
|
447
|
+
* Checks whether the given category is the meta logger's category or one of
|
|
448
|
+
* its descendants, to which category prefixes do not apply.
|
|
449
|
+
*/
|
|
198
450
|
function isMetaLoggerCategory(category) {
|
|
199
451
|
return category.length >= 2 && category[0] === "logtape" && category[1] === "meta";
|
|
200
452
|
}
|
|
@@ -209,9 +461,15 @@ var LoggerImpl = class LoggerImpl {
|
|
|
209
461
|
sinks;
|
|
210
462
|
filters;
|
|
211
463
|
contextLocalStorage;
|
|
464
|
+
/**
|
|
465
|
+
* Whether to capture source locations for this logger and its
|
|
466
|
+
* descendants. `undefined` inherits the setting from the parent.
|
|
467
|
+
*/
|
|
468
|
+
sourceLocationCapture = void 0;
|
|
212
469
|
#parentSinks = "inherit";
|
|
213
470
|
#lowestLevel = "trace";
|
|
214
471
|
#sinkPlanCache = {};
|
|
472
|
+
#forwardPlanCache = void 0;
|
|
215
473
|
static getLogger(category = []) {
|
|
216
474
|
let rootLogger = globalRootLoggerSymbol in globalThis ? globalThis[globalRootLoggerSymbol] ?? null : null;
|
|
217
475
|
if (rootLogger == null) {
|
|
@@ -272,6 +530,7 @@ var LoggerImpl = class LoggerImpl {
|
|
|
272
530
|
this.parentSinks = "inherit";
|
|
273
531
|
while (this.filters.length > 0) this.filters.shift();
|
|
274
532
|
this.lowestLevel = "trace";
|
|
533
|
+
this.sourceLocationCapture = void 0;
|
|
275
534
|
}
|
|
276
535
|
/**
|
|
277
536
|
* Reset the logger and all its descendants. This removes all sinks and
|
|
@@ -287,6 +546,71 @@ var LoggerImpl = class LoggerImpl {
|
|
|
287
546
|
with(properties) {
|
|
288
547
|
return new LoggerCtx(this, { ...properties });
|
|
289
548
|
}
|
|
549
|
+
/**
|
|
550
|
+
* Sets whether the global configuration enables source location capture
|
|
551
|
+
* for any category. Call this on the root logger only.
|
|
552
|
+
*/
|
|
553
|
+
setGlobalSourceLocationCapture(enabled) {
|
|
554
|
+
globalSourceLocationCapture = enabled;
|
|
555
|
+
}
|
|
556
|
+
/**
|
|
557
|
+
* Records that a scoped configuration which enables source location
|
|
558
|
+
* capture for some category became active. Call this on the root logger
|
|
559
|
+
* only, and balance it with
|
|
560
|
+
* {@link LoggerImpl.releaseScopedSourceLocationCapture}.
|
|
561
|
+
*/
|
|
562
|
+
retainScopedSourceLocationCapture() {
|
|
563
|
+
scopedSourceLocationCaptures++;
|
|
564
|
+
}
|
|
565
|
+
/**
|
|
566
|
+
* Records that a scoped configuration retained with
|
|
567
|
+
* {@link LoggerImpl.retainScopedSourceLocationCapture} ended. Call this on
|
|
568
|
+
* the root logger only.
|
|
569
|
+
*/
|
|
570
|
+
releaseScopedSourceLocationCapture() {
|
|
571
|
+
if (scopedSourceLocationCaptures > 0) scopedSourceLocationCaptures--;
|
|
572
|
+
}
|
|
573
|
+
/**
|
|
574
|
+
* Captures where user code called the public logging method that called
|
|
575
|
+
* this method, if source location capture is enabled for this logger and
|
|
576
|
+
* a record of the given level could be emitted.
|
|
577
|
+
*
|
|
578
|
+
* It must be called directly by the public logging method that user code
|
|
579
|
+
* called (e.g., {@link LoggerImpl.info} or {@link LoggerCtx.info}), and
|
|
580
|
+
* not in tail position, because the location is read from the third frame
|
|
581
|
+
* of a stack trace constructed here: this method, the logging method, and
|
|
582
|
+
* then its caller. JavaScriptCore implements proper tail calls, so a call
|
|
583
|
+
* in tail position would remove the logging method's frame.
|
|
584
|
+
* @param level The log level of the record to be made.
|
|
585
|
+
* @returns The source location, or `undefined` if capture is disabled, the
|
|
586
|
+
* record would certainly be dropped, or the stack trace could not
|
|
587
|
+
* be parsed.
|
|
588
|
+
*/
|
|
589
|
+
captureSourceLocation(level) {
|
|
590
|
+
if (isMetaLoggerCategory(this.category)) return void 0;
|
|
591
|
+
const categoryPrefix = getCategoryPrefix();
|
|
592
|
+
const scopedConfig = getCurrentScopedConfig(LoggerImpl.getLogger().contextLocalStorage);
|
|
593
|
+
if (scopedConfig != null) {
|
|
594
|
+
const category = categoryPrefix.length > 0 ? [...categoryPrefix, ...this.category] : this.category;
|
|
595
|
+
if (!scopedConfigHasSink(scopedConfig, category, level) || !scopedConfigCapturesSourceLocation(scopedConfig, category)) return void 0;
|
|
596
|
+
} else {
|
|
597
|
+
const dispatcher = this.getDispatcher(categoryPrefix);
|
|
598
|
+
if (dispatcher.isCertainlyDroppedResolved(level) || !dispatcher.capturesSourceLocation()) return void 0;
|
|
599
|
+
}
|
|
600
|
+
try {
|
|
601
|
+
return parseSourceLocation((/* @__PURE__ */ new Error()).stack, 2);
|
|
602
|
+
} catch {
|
|
603
|
+
return;
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
/**
|
|
607
|
+
* Resolves whether this logger or the nearest ancestor that configures it
|
|
608
|
+
* captures source locations.
|
|
609
|
+
*/
|
|
610
|
+
capturesSourceLocation() {
|
|
611
|
+
if (this.sourceLocationCapture != null) return this.sourceLocationCapture;
|
|
612
|
+
return this.parent?.capturesSourceLocation() ?? false;
|
|
613
|
+
}
|
|
290
614
|
filter(record) {
|
|
291
615
|
for (const filter of this.filters) if (!filter(record)) return false;
|
|
292
616
|
if (this.filters.length < 1) return this.parent?.filter(record) ?? true;
|
|
@@ -307,17 +631,45 @@ var LoggerImpl = class LoggerImpl {
|
|
|
307
631
|
getSinkDispatchPlan(level) {
|
|
308
632
|
const cached = this.#sinkPlanCache[level];
|
|
309
633
|
if (cached != null && this.isSinkDispatchPlanFresh(level, cached)) return cached;
|
|
310
|
-
const
|
|
311
|
-
const plan = this.createSinkDispatchPlan(level, parentPlan);
|
|
634
|
+
const plan = this.createSinkDispatchPlan(level, this.resolveParentPlan(level));
|
|
312
635
|
this.#sinkPlanCache[level] = plan;
|
|
313
636
|
return plan;
|
|
314
637
|
}
|
|
638
|
+
resolveParentPlan(level) {
|
|
639
|
+
if (this.parent == null) return void 0;
|
|
640
|
+
if (this.parentSinks === "inherit") return this.parent.getSinkDispatchPlan(level);
|
|
641
|
+
if (this.parentSinks === "forward") return this.parent.getForwardSinkPlan();
|
|
642
|
+
}
|
|
315
643
|
isSinkDispatchPlanFresh(level, plan) {
|
|
316
644
|
if (plan.lowestLevel !== this.lowestLevel || plan.parentSinks !== this.parentSinks || plan.localSinks.length !== this.sinks.length) return false;
|
|
317
645
|
for (let i = 0; i < plan.localSinks.length; i++) if (plan.localSinks[i] !== this.sinks[i]) return false;
|
|
318
|
-
|
|
646
|
+
return plan.parentPlan === this.resolveParentPlan(level);
|
|
647
|
+
}
|
|
648
|
+
getForwardSinkPlan() {
|
|
649
|
+
const cached = this.#forwardPlanCache;
|
|
650
|
+
if (cached != null && this.isForwardSinkPlanFresh(cached)) return cached;
|
|
651
|
+
const parentPlan = this.parent != null && this.parentSinks !== "override" ? this.parent.getForwardSinkPlan() : void 0;
|
|
652
|
+
const plan = this.createForwardSinkPlan(parentPlan);
|
|
653
|
+
this.#forwardPlanCache = plan;
|
|
654
|
+
return plan;
|
|
655
|
+
}
|
|
656
|
+
isForwardSinkPlanFresh(plan) {
|
|
657
|
+
if (plan.parentSinks !== this.parentSinks || plan.localSinks.length !== this.sinks.length) return false;
|
|
658
|
+
for (let i = 0; i < plan.localSinks.length; i++) if (plan.localSinks[i] !== this.sinks[i]) return false;
|
|
659
|
+
const parentPlan = this.parent != null && this.parentSinks !== "override" ? this.parent.getForwardSinkPlan() : void 0;
|
|
319
660
|
return plan.parentPlan === parentPlan;
|
|
320
661
|
}
|
|
662
|
+
createForwardSinkPlan(parentPlan) {
|
|
663
|
+
const localSinks = [...this.sinks];
|
|
664
|
+
const sinks = parentPlan == null || parentPlan.sinks.length < 1 ? localSinks : [...parentPlan.sinks, ...localSinks];
|
|
665
|
+
return {
|
|
666
|
+
kind: "forward",
|
|
667
|
+
localSinks,
|
|
668
|
+
parentSinks: this.parentSinks,
|
|
669
|
+
parentPlan,
|
|
670
|
+
sinks
|
|
671
|
+
};
|
|
672
|
+
}
|
|
321
673
|
createSinkDispatchPlan(level, parentPlan) {
|
|
322
674
|
const state = {
|
|
323
675
|
localSinks: [...this.sinks],
|
|
@@ -343,6 +695,10 @@ var LoggerImpl = class LoggerImpl {
|
|
|
343
695
|
if (parentPlan != null) {
|
|
344
696
|
if (parentPlan.kind === "one") firstSink = parentPlan.sink;
|
|
345
697
|
else if (parentPlan.kind === "many") sinks = [...parentPlan.sinks];
|
|
698
|
+
else if (parentPlan.kind === "forward") {
|
|
699
|
+
if (parentPlan.sinks.length === 1) firstSink = parentPlan.sinks[0];
|
|
700
|
+
else if (parentPlan.sinks.length > 1) sinks = [...parentPlan.sinks];
|
|
701
|
+
}
|
|
346
702
|
}
|
|
347
703
|
for (const sink of state.localSinks) appendSink(sink);
|
|
348
704
|
if (sinks != null) return {
|
|
@@ -362,10 +718,75 @@ var LoggerImpl = class LoggerImpl {
|
|
|
362
718
|
}
|
|
363
719
|
isEnabledFor(level) {
|
|
364
720
|
const categoryPrefix = isMetaLoggerCategory(this.category) ? [] : getCategoryPrefix();
|
|
365
|
-
|
|
721
|
+
const scopedConfig = getCurrentScopedConfig(LoggerImpl.getLogger().contextLocalStorage);
|
|
722
|
+
if (scopedConfig != null) return scopedConfigHasSink(scopedConfig, categoryPrefix.length > 0 ? [...categoryPrefix, ...this.category] : this.category, level);
|
|
723
|
+
return this.getDispatcher(categoryPrefix).isEnabledForResolved(level);
|
|
724
|
+
}
|
|
725
|
+
/**
|
|
726
|
+
* Checks whether a record of the given level logged through this logger
|
|
727
|
+
* would certainly be dropped without being seen by any filter or sink.
|
|
728
|
+
* Logging methods use this to return before building a record.
|
|
729
|
+
*
|
|
730
|
+
* This assumes the context-local storage's store does not change between
|
|
731
|
+
* synchronous reads within a single logging call, which holds for
|
|
732
|
+
* `AsyncLocalStorage` and for the stores set up by `withContext()`,
|
|
733
|
+
* `withCategoryPrefix()`, and `withConfig()`.
|
|
734
|
+
* @param level The log level of the record.
|
|
735
|
+
* @returns `true` if emitting such a record would have no observable
|
|
736
|
+
* effect, `false` otherwise.
|
|
737
|
+
*/
|
|
738
|
+
isCertainlyDropped(level) {
|
|
739
|
+
const categoryPrefix = isMetaLoggerCategory(this.category) ? [] : getCategoryPrefix();
|
|
740
|
+
const scopedConfig = getCurrentScopedConfig(LoggerImpl.getLogger().contextLocalStorage);
|
|
741
|
+
if (scopedConfig != null) return !scopedConfigHasSink(scopedConfig, categoryPrefix.length > 0 ? [...categoryPrefix, ...this.category] : this.category, level);
|
|
742
|
+
return this.getDispatcher(categoryPrefix).isCertainlyDroppedResolved(level);
|
|
743
|
+
}
|
|
744
|
+
/**
|
|
745
|
+
* Checks whether a record of the given level dispatched by this logger,
|
|
746
|
+
* without a scoped configuration, would certainly be dropped. See
|
|
747
|
+
* {@link LoggerImpl.isCertainlyDropped}.
|
|
748
|
+
*/
|
|
749
|
+
isCertainlyDroppedResolved(level) {
|
|
750
|
+
if (this.lowestLevel === null || compareLogLevel(level, this.lowestLevel) < 0) return true;
|
|
751
|
+
return !this.isEnabledForResolved(level) && !this.hasEffectiveFilters();
|
|
366
752
|
}
|
|
753
|
+
/**
|
|
754
|
+
* Resolves the logger that actually dispatches records logged through this
|
|
755
|
+
* logger under the given category prefix. It must stay in sync with
|
|
756
|
+
* the dispatcher resolution in {@link LoggerImpl.emit}.
|
|
757
|
+
*/
|
|
758
|
+
getDispatcher(categoryPrefix) {
|
|
759
|
+
return categoryPrefix.length > 0 ? LoggerImpl.getNearestExistingLogger([...categoryPrefix, ...this.category]) : this;
|
|
760
|
+
}
|
|
761
|
+
/**
|
|
762
|
+
* Checks whether {@link LoggerImpl.filter} would run any filter, i.e.,
|
|
763
|
+
* whether this logger or any of its ancestors has a filter.
|
|
764
|
+
*/
|
|
765
|
+
hasEffectiveFilters() {
|
|
766
|
+
if (this.filters.length > 0) return true;
|
|
767
|
+
return this.parent?.hasEffectiveFilters() ?? false;
|
|
768
|
+
}
|
|
769
|
+
/**
|
|
770
|
+
* Checks whether {@link LoggerImpl.getSinks} would yield any sink for
|
|
771
|
+
* the given level, without building or validating sink dispatch plans.
|
|
772
|
+
* It must stay in sync with {@link LoggerImpl.createSinkDispatchPlan}.
|
|
773
|
+
*/
|
|
367
774
|
isEnabledForResolved(level) {
|
|
368
|
-
|
|
775
|
+
if (this.lowestLevel === null || compareLogLevel(level, this.lowestLevel) < 0) return false;
|
|
776
|
+
if (this.sinks.length > 0) return true;
|
|
777
|
+
if (this.parent == null) return false;
|
|
778
|
+
if (this.parentSinks === "inherit") return this.parent.isEnabledForResolved(level);
|
|
779
|
+
if (this.parentSinks === "forward") return this.parent.hasForwardSinks();
|
|
780
|
+
return false;
|
|
781
|
+
}
|
|
782
|
+
/**
|
|
783
|
+
* Checks whether {@link LoggerImpl.getForwardSinkPlan} would collect any
|
|
784
|
+
* sink, i.e., whether this logger or an ancestor up to and including the
|
|
785
|
+
* nearest one whose `parentSinks` is `"override"` has local sinks.
|
|
786
|
+
*/
|
|
787
|
+
hasForwardSinks() {
|
|
788
|
+
if (this.sinks.length > 0) return true;
|
|
789
|
+
return this.parent != null && this.parentSinks !== "override" && this.parent.hasForwardSinks();
|
|
369
790
|
}
|
|
370
791
|
emit(record, bypassSinks) {
|
|
371
792
|
const baseCategory = "category" in record ? record.category : this.category;
|
|
@@ -385,6 +806,32 @@ var LoggerImpl = class LoggerImpl {
|
|
|
385
806
|
(categoryPrefix.length > 0 ? LoggerImpl.getNearestExistingLogger(fullCategory) : this).emitResolved(fullRecord, bypassSinks);
|
|
386
807
|
}
|
|
387
808
|
emitResolved(record, bypassSinks) {
|
|
809
|
+
const scopedConfig = getCurrentScopedConfig(LoggerImpl.getLogger().contextLocalStorage);
|
|
810
|
+
if (scopedConfig != null) {
|
|
811
|
+
let snapshot$1;
|
|
812
|
+
let snapshotFailed$1 = false;
|
|
813
|
+
emitWithScopedConfig(scopedConfig, record, bypassSinks, (sink, activeBypassSinks) => {
|
|
814
|
+
try {
|
|
815
|
+
if (shouldSnapshotForSink(sink)) try {
|
|
816
|
+
snapshot$1 ??= snapshotLogRecordProperties(record);
|
|
817
|
+
} catch {
|
|
818
|
+
snapshotFailed$1 = true;
|
|
819
|
+
snapshot$1 = record;
|
|
820
|
+
}
|
|
821
|
+
sink(snapshot$1 ?? record);
|
|
822
|
+
} catch (error) {
|
|
823
|
+
const bypassSinks2 = new Set(activeBypassSinks);
|
|
824
|
+
bypassSinks2.add(sink);
|
|
825
|
+
metaLogger.log("fatal", "Failed to emit a log record to sink {sink}: {error}", {
|
|
826
|
+
sink,
|
|
827
|
+
error,
|
|
828
|
+
record
|
|
829
|
+
}, bypassSinks2);
|
|
830
|
+
}
|
|
831
|
+
if (snapshotFailed$1) snapshot$1 = record;
|
|
832
|
+
});
|
|
833
|
+
return;
|
|
834
|
+
}
|
|
388
835
|
if (this.lowestLevel === null || compareLogLevel(record.level, this.lowestLevel) < 0 || !this.filter(record)) return;
|
|
389
836
|
const plan = this.getSinkDispatchPlan(record.level);
|
|
390
837
|
if (plan.kind === "none") return;
|
|
@@ -433,7 +880,8 @@ var LoggerImpl = class LoggerImpl {
|
|
|
433
880
|
}
|
|
434
881
|
}
|
|
435
882
|
}
|
|
436
|
-
log(level, rawMessage, properties, bypassSinks) {
|
|
883
|
+
log(level, rawMessage, properties, bypassSinks, sourceLocation) {
|
|
884
|
+
if (this.isCertainlyDropped(level)) return;
|
|
437
885
|
const implicitContext = getImplicitContextIfAny();
|
|
438
886
|
if (typeof properties !== "function" && implicitContext == null && !rawMessage.includes("{") && !hasEnumerableProperties(properties)) {
|
|
439
887
|
const record$1 = {
|
|
@@ -444,6 +892,7 @@ var LoggerImpl = class LoggerImpl {
|
|
|
444
892
|
timestamp: Date.now(),
|
|
445
893
|
properties: {}
|
|
446
894
|
};
|
|
895
|
+
attachSourceLocation(record$1, sourceLocation);
|
|
447
896
|
resolvedStringLogRecords.add(record$1);
|
|
448
897
|
this.emit(record$1, bypassSinks);
|
|
449
898
|
return;
|
|
@@ -483,10 +932,12 @@ var LoggerImpl = class LoggerImpl {
|
|
|
483
932
|
return cachedProps;
|
|
484
933
|
}
|
|
485
934
|
};
|
|
935
|
+
attachSourceLocation(record, sourceLocation);
|
|
486
936
|
internalStringLogRecords.add(record);
|
|
487
937
|
this.emit(record, bypassSinks);
|
|
488
938
|
}
|
|
489
|
-
logLazily(level, callback, properties = {}) {
|
|
939
|
+
logLazily(level, callback, properties = {}, sourceLocation) {
|
|
940
|
+
if (this.isCertainlyDropped(level)) return;
|
|
490
941
|
const implicitContext = getImplicitContextIfAny();
|
|
491
942
|
let rawMessage = void 0;
|
|
492
943
|
let msg = void 0;
|
|
@@ -500,7 +951,7 @@ var LoggerImpl = class LoggerImpl {
|
|
|
500
951
|
}
|
|
501
952
|
return [msg, rawMessage];
|
|
502
953
|
}
|
|
503
|
-
|
|
954
|
+
const record = {
|
|
504
955
|
category: this.category,
|
|
505
956
|
level,
|
|
506
957
|
get message() {
|
|
@@ -514,11 +965,14 @@ var LoggerImpl = class LoggerImpl {
|
|
|
514
965
|
...implicitContext ?? {},
|
|
515
966
|
...properties
|
|
516
967
|
}
|
|
517
|
-
}
|
|
968
|
+
};
|
|
969
|
+
attachSourceLocation(record, sourceLocation);
|
|
970
|
+
this.emit(record);
|
|
518
971
|
}
|
|
519
|
-
logTemplate(level, messageTemplate, values, properties = {}) {
|
|
972
|
+
logTemplate(level, messageTemplate, values, properties = {}, sourceLocation) {
|
|
973
|
+
if (this.isCertainlyDropped(level)) return;
|
|
520
974
|
const implicitContext = getImplicitContextIfAny();
|
|
521
|
-
|
|
975
|
+
const record = {
|
|
522
976
|
category: this.category,
|
|
523
977
|
level,
|
|
524
978
|
message: renderMessage(messageTemplate, values),
|
|
@@ -528,32 +982,37 @@ var LoggerImpl = class LoggerImpl {
|
|
|
528
982
|
...implicitContext ?? {},
|
|
529
983
|
...properties
|
|
530
984
|
}
|
|
531
|
-
}
|
|
985
|
+
};
|
|
986
|
+
attachSourceLocation(record, sourceLocation);
|
|
987
|
+
this.emit(record);
|
|
532
988
|
}
|
|
533
989
|
trace(message, ...values) {
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
else if (
|
|
537
|
-
else this.
|
|
990
|
+
const sourceLocation = isSourceLocationCaptureActive() ? this.captureSourceLocation("trace") : void 0;
|
|
991
|
+
if (typeof message === "string") return logStringMessage(this, "trace", message, values[0], sourceLocation);
|
|
992
|
+
else if (typeof message === "function") this.logLazily("trace", message, void 0, sourceLocation);
|
|
993
|
+
else if (!Array.isArray(message)) this.log("trace", "{*}", message, void 0, sourceLocation);
|
|
994
|
+
else this.logTemplate("trace", message, values, void 0, sourceLocation);
|
|
538
995
|
}
|
|
539
996
|
debug(message, ...values) {
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
else if (
|
|
543
|
-
else this.
|
|
997
|
+
const sourceLocation = isSourceLocationCaptureActive() ? this.captureSourceLocation("debug") : void 0;
|
|
998
|
+
if (typeof message === "string") return logStringMessage(this, "debug", message, values[0], sourceLocation);
|
|
999
|
+
else if (typeof message === "function") this.logLazily("debug", message, void 0, sourceLocation);
|
|
1000
|
+
else if (!Array.isArray(message)) this.log("debug", "{*}", message, void 0, sourceLocation);
|
|
1001
|
+
else this.logTemplate("debug", message, values, void 0, sourceLocation);
|
|
544
1002
|
}
|
|
545
1003
|
info(message, ...values) {
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
else if (
|
|
549
|
-
else this.
|
|
1004
|
+
const sourceLocation = isSourceLocationCaptureActive() ? this.captureSourceLocation("info") : void 0;
|
|
1005
|
+
if (typeof message === "string") return logStringMessage(this, "info", message, values[0], sourceLocation);
|
|
1006
|
+
else if (typeof message === "function") this.logLazily("info", message, void 0, sourceLocation);
|
|
1007
|
+
else if (!Array.isArray(message)) this.log("info", "{*}", message, void 0, sourceLocation);
|
|
1008
|
+
else this.logTemplate("info", message, values, void 0, sourceLocation);
|
|
550
1009
|
}
|
|
551
|
-
logError(level, error, props) {
|
|
1010
|
+
logError(level, error, props, sourceLocation) {
|
|
552
1011
|
if (typeof props !== "function") {
|
|
553
1012
|
this.log(level, "{error.message}", {
|
|
554
1013
|
...props,
|
|
555
1014
|
error
|
|
556
|
-
});
|
|
1015
|
+
}, void 0, sourceLocation);
|
|
557
1016
|
return;
|
|
558
1017
|
}
|
|
559
1018
|
if (!this.isEnabledFor(level)) return Promise.resolve();
|
|
@@ -562,44 +1021,48 @@ var LoggerImpl = class LoggerImpl {
|
|
|
562
1021
|
this.log(level, "{error.message}", {
|
|
563
1022
|
...resolved,
|
|
564
1023
|
error
|
|
565
|
-
});
|
|
1024
|
+
}, void 0, sourceLocation);
|
|
566
1025
|
});
|
|
567
1026
|
this.log(level, "{error.message}", {
|
|
568
1027
|
...result,
|
|
569
1028
|
error
|
|
570
|
-
});
|
|
1029
|
+
}, void 0, sourceLocation);
|
|
571
1030
|
}
|
|
572
1031
|
warn(message, ...values) {
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
else if (typeof message === "string")
|
|
576
|
-
else if (typeof message === "
|
|
577
|
-
else if (
|
|
578
|
-
else this.
|
|
1032
|
+
const sourceLocation = isSourceLocationCaptureActive() ? this.captureSourceLocation("warning") : void 0;
|
|
1033
|
+
if (message instanceof Error) return this.logError("warning", message, values[0], sourceLocation);
|
|
1034
|
+
else if (typeof message === "string" && values[0] instanceof Error) this.log("warning", message, { error: values[0] }, void 0, sourceLocation);
|
|
1035
|
+
else if (typeof message === "string") return logStringMessage(this, "warning", message, values[0], sourceLocation);
|
|
1036
|
+
else if (typeof message === "function") this.logLazily("warning", message, void 0, sourceLocation);
|
|
1037
|
+
else if (!Array.isArray(message)) this.log("warning", "{*}", message, void 0, sourceLocation);
|
|
1038
|
+
else this.logTemplate("warning", message, values, void 0, sourceLocation);
|
|
579
1039
|
}
|
|
580
1040
|
warning(message, ...values) {
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
else if (typeof message === "string")
|
|
584
|
-
else if (typeof message === "
|
|
585
|
-
else if (
|
|
586
|
-
else this.
|
|
1041
|
+
const sourceLocation = isSourceLocationCaptureActive() ? this.captureSourceLocation("warning") : void 0;
|
|
1042
|
+
if (message instanceof Error) return this.logError("warning", message, values[0], sourceLocation);
|
|
1043
|
+
else if (typeof message === "string" && values[0] instanceof Error) this.log("warning", message, { error: values[0] }, void 0, sourceLocation);
|
|
1044
|
+
else if (typeof message === "string") return logStringMessage(this, "warning", message, values[0], sourceLocation);
|
|
1045
|
+
else if (typeof message === "function") this.logLazily("warning", message, void 0, sourceLocation);
|
|
1046
|
+
else if (!Array.isArray(message)) this.log("warning", "{*}", message, void 0, sourceLocation);
|
|
1047
|
+
else this.logTemplate("warning", message, values, void 0, sourceLocation);
|
|
587
1048
|
}
|
|
588
1049
|
error(message, ...values) {
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
else if (typeof message === "string")
|
|
592
|
-
else if (typeof message === "
|
|
593
|
-
else if (
|
|
594
|
-
else this.
|
|
1050
|
+
const sourceLocation = isSourceLocationCaptureActive() ? this.captureSourceLocation("error") : void 0;
|
|
1051
|
+
if (message instanceof Error) return this.logError("error", message, values[0], sourceLocation);
|
|
1052
|
+
else if (typeof message === "string" && values[0] instanceof Error) this.log("error", message, { error: values[0] }, void 0, sourceLocation);
|
|
1053
|
+
else if (typeof message === "string") return logStringMessage(this, "error", message, values[0], sourceLocation);
|
|
1054
|
+
else if (typeof message === "function") this.logLazily("error", message, void 0, sourceLocation);
|
|
1055
|
+
else if (!Array.isArray(message)) this.log("error", "{*}", message, void 0, sourceLocation);
|
|
1056
|
+
else this.logTemplate("error", message, values, void 0, sourceLocation);
|
|
595
1057
|
}
|
|
596
1058
|
fatal(message, ...values) {
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
else if (typeof message === "string")
|
|
600
|
-
else if (typeof message === "
|
|
601
|
-
else if (
|
|
602
|
-
else this.
|
|
1059
|
+
const sourceLocation = isSourceLocationCaptureActive() ? this.captureSourceLocation("fatal") : void 0;
|
|
1060
|
+
if (message instanceof Error) return this.logError("fatal", message, values[0], sourceLocation);
|
|
1061
|
+
else if (typeof message === "string" && values[0] instanceof Error) this.log("fatal", message, { error: values[0] }, void 0, sourceLocation);
|
|
1062
|
+
else if (typeof message === "string") return logStringMessage(this, "fatal", message, values[0], sourceLocation);
|
|
1063
|
+
else if (typeof message === "function") this.logLazily("fatal", message, void 0, sourceLocation);
|
|
1064
|
+
else if (!Array.isArray(message)) this.log("fatal", "{*}", message, void 0, sourceLocation);
|
|
1065
|
+
else this.logTemplate("fatal", message, values, void 0, sourceLocation);
|
|
603
1066
|
}
|
|
604
1067
|
};
|
|
605
1068
|
/**
|
|
@@ -629,7 +1092,8 @@ var LoggerCtx = class LoggerCtx {
|
|
|
629
1092
|
...properties
|
|
630
1093
|
});
|
|
631
1094
|
}
|
|
632
|
-
log(level, message, properties, bypassSinks) {
|
|
1095
|
+
log(level, message, properties, bypassSinks, sourceLocation) {
|
|
1096
|
+
if (this.logger.isCertainlyDropped(level)) return;
|
|
633
1097
|
const contextProps = this.properties;
|
|
634
1098
|
this.logger.log(level, message, typeof properties === "function" ? () => resolveProperties({
|
|
635
1099
|
...contextProps,
|
|
@@ -637,13 +1101,15 @@ var LoggerCtx = class LoggerCtx {
|
|
|
637
1101
|
}) : () => resolveProperties({
|
|
638
1102
|
...contextProps,
|
|
639
1103
|
...properties
|
|
640
|
-
}), bypassSinks);
|
|
1104
|
+
}), bypassSinks, sourceLocation);
|
|
641
1105
|
}
|
|
642
|
-
logLazily(level, callback) {
|
|
643
|
-
this.logger.
|
|
1106
|
+
logLazily(level, callback, sourceLocation) {
|
|
1107
|
+
if (this.logger.isCertainlyDropped(level)) return;
|
|
1108
|
+
this.logger.logLazily(level, callback, resolveProperties(this.properties), sourceLocation);
|
|
644
1109
|
}
|
|
645
|
-
logTemplate(level, messageTemplate, values) {
|
|
646
|
-
this.logger.
|
|
1110
|
+
logTemplate(level, messageTemplate, values, sourceLocation) {
|
|
1111
|
+
if (this.logger.isCertainlyDropped(level)) return;
|
|
1112
|
+
this.logger.logTemplate(level, messageTemplate, values, resolveProperties(this.properties), sourceLocation);
|
|
647
1113
|
}
|
|
648
1114
|
emit(record) {
|
|
649
1115
|
const recordWithContext = {
|
|
@@ -659,29 +1125,32 @@ var LoggerCtx = class LoggerCtx {
|
|
|
659
1125
|
return this.logger.isEnabledFor(level);
|
|
660
1126
|
}
|
|
661
1127
|
trace(message, ...values) {
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
else if (
|
|
665
|
-
else this.
|
|
1128
|
+
const sourceLocation = isSourceLocationCaptureActive() ? this.logger.captureSourceLocation("trace") : void 0;
|
|
1129
|
+
if (typeof message === "string") return logStringMessage(this, "trace", message, values[0], sourceLocation);
|
|
1130
|
+
else if (typeof message === "function") this.logLazily("trace", message, sourceLocation);
|
|
1131
|
+
else if (!Array.isArray(message)) this.log("trace", "{*}", message, void 0, sourceLocation);
|
|
1132
|
+
else this.logTemplate("trace", message, values, sourceLocation);
|
|
666
1133
|
}
|
|
667
1134
|
debug(message, ...values) {
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
else if (
|
|
671
|
-
else this.
|
|
1135
|
+
const sourceLocation = isSourceLocationCaptureActive() ? this.logger.captureSourceLocation("debug") : void 0;
|
|
1136
|
+
if (typeof message === "string") return logStringMessage(this, "debug", message, values[0], sourceLocation);
|
|
1137
|
+
else if (typeof message === "function") this.logLazily("debug", message, sourceLocation);
|
|
1138
|
+
else if (!Array.isArray(message)) this.log("debug", "{*}", message, void 0, sourceLocation);
|
|
1139
|
+
else this.logTemplate("debug", message, values, sourceLocation);
|
|
672
1140
|
}
|
|
673
1141
|
info(message, ...values) {
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
else if (
|
|
677
|
-
else this.
|
|
1142
|
+
const sourceLocation = isSourceLocationCaptureActive() ? this.logger.captureSourceLocation("info") : void 0;
|
|
1143
|
+
if (typeof message === "string") return logStringMessage(this, "info", message, values[0], sourceLocation);
|
|
1144
|
+
else if (typeof message === "function") this.logLazily("info", message, sourceLocation);
|
|
1145
|
+
else if (!Array.isArray(message)) this.log("info", "{*}", message, void 0, sourceLocation);
|
|
1146
|
+
else this.logTemplate("info", message, values, sourceLocation);
|
|
678
1147
|
}
|
|
679
|
-
logError(level, error, props) {
|
|
1148
|
+
logError(level, error, props, sourceLocation) {
|
|
680
1149
|
if (typeof props !== "function") {
|
|
681
1150
|
this.log(level, "{error.message}", {
|
|
682
1151
|
...props,
|
|
683
1152
|
error
|
|
684
|
-
});
|
|
1153
|
+
}, void 0, sourceLocation);
|
|
685
1154
|
return;
|
|
686
1155
|
}
|
|
687
1156
|
if (!this.isEnabledFor(level)) return Promise.resolve();
|
|
@@ -690,44 +1159,48 @@ var LoggerCtx = class LoggerCtx {
|
|
|
690
1159
|
this.log(level, "{error.message}", {
|
|
691
1160
|
...resolved,
|
|
692
1161
|
error
|
|
693
|
-
});
|
|
1162
|
+
}, void 0, sourceLocation);
|
|
694
1163
|
});
|
|
695
1164
|
this.log(level, "{error.message}", {
|
|
696
1165
|
...result,
|
|
697
1166
|
error
|
|
698
|
-
});
|
|
1167
|
+
}, void 0, sourceLocation);
|
|
699
1168
|
}
|
|
700
1169
|
warn(message, ...values) {
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
else if (typeof message === "string")
|
|
704
|
-
else if (typeof message === "
|
|
705
|
-
else if (
|
|
706
|
-
else this.
|
|
1170
|
+
const sourceLocation = isSourceLocationCaptureActive() ? this.logger.captureSourceLocation("warning") : void 0;
|
|
1171
|
+
if (message instanceof Error) return this.logError("warning", message, values[0], sourceLocation);
|
|
1172
|
+
else if (typeof message === "string" && values[0] instanceof Error) this.log("warning", message, { error: values[0] }, void 0, sourceLocation);
|
|
1173
|
+
else if (typeof message === "string") return logStringMessage(this, "warning", message, values[0], sourceLocation);
|
|
1174
|
+
else if (typeof message === "function") this.logLazily("warning", message, sourceLocation);
|
|
1175
|
+
else if (!Array.isArray(message)) this.log("warning", "{*}", message, void 0, sourceLocation);
|
|
1176
|
+
else this.logTemplate("warning", message, values, sourceLocation);
|
|
707
1177
|
}
|
|
708
1178
|
warning(message, ...values) {
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
else if (typeof message === "string")
|
|
712
|
-
else if (typeof message === "
|
|
713
|
-
else if (
|
|
714
|
-
else this.
|
|
1179
|
+
const sourceLocation = isSourceLocationCaptureActive() ? this.logger.captureSourceLocation("warning") : void 0;
|
|
1180
|
+
if (message instanceof Error) return this.logError("warning", message, values[0], sourceLocation);
|
|
1181
|
+
else if (typeof message === "string" && values[0] instanceof Error) this.log("warning", message, { error: values[0] }, void 0, sourceLocation);
|
|
1182
|
+
else if (typeof message === "string") return logStringMessage(this, "warning", message, values[0], sourceLocation);
|
|
1183
|
+
else if (typeof message === "function") this.logLazily("warning", message, sourceLocation);
|
|
1184
|
+
else if (!Array.isArray(message)) this.log("warning", "{*}", message, void 0, sourceLocation);
|
|
1185
|
+
else this.logTemplate("warning", message, values, sourceLocation);
|
|
715
1186
|
}
|
|
716
1187
|
error(message, ...values) {
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
else if (typeof message === "string")
|
|
720
|
-
else if (typeof message === "
|
|
721
|
-
else if (
|
|
722
|
-
else this.
|
|
1188
|
+
const sourceLocation = isSourceLocationCaptureActive() ? this.logger.captureSourceLocation("error") : void 0;
|
|
1189
|
+
if (message instanceof Error) return this.logError("error", message, values[0], sourceLocation);
|
|
1190
|
+
else if (typeof message === "string" && values[0] instanceof Error) this.log("error", message, { error: values[0] }, void 0, sourceLocation);
|
|
1191
|
+
else if (typeof message === "string") return logStringMessage(this, "error", message, values[0], sourceLocation);
|
|
1192
|
+
else if (typeof message === "function") this.logLazily("error", message, sourceLocation);
|
|
1193
|
+
else if (!Array.isArray(message)) this.log("error", "{*}", message, void 0, sourceLocation);
|
|
1194
|
+
else this.logTemplate("error", message, values, sourceLocation);
|
|
723
1195
|
}
|
|
724
1196
|
fatal(message, ...values) {
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
else if (typeof message === "string")
|
|
728
|
-
else if (typeof message === "
|
|
729
|
-
else if (
|
|
730
|
-
else this.
|
|
1197
|
+
const sourceLocation = isSourceLocationCaptureActive() ? this.logger.captureSourceLocation("fatal") : void 0;
|
|
1198
|
+
if (message instanceof Error) return this.logError("fatal", message, values[0], sourceLocation);
|
|
1199
|
+
else if (typeof message === "string" && values[0] instanceof Error) this.log("fatal", message, { error: values[0] }, void 0, sourceLocation);
|
|
1200
|
+
else if (typeof message === "string") return logStringMessage(this, "fatal", message, values[0], sourceLocation);
|
|
1201
|
+
else if (typeof message === "function") this.logLazily("fatal", message, sourceLocation);
|
|
1202
|
+
else if (!Array.isArray(message)) this.log("fatal", "{*}", message, void 0, sourceLocation);
|
|
1203
|
+
else this.logTemplate("fatal", message, values, sourceLocation);
|
|
731
1204
|
}
|
|
732
1205
|
};
|
|
733
1206
|
/**
|
|
@@ -1004,44 +1477,226 @@ function renderMessage(template, values) {
|
|
|
1004
1477
|
}
|
|
1005
1478
|
return args;
|
|
1006
1479
|
}
|
|
1007
|
-
|
|
1008
|
-
//#region node_modules/.pnpm/@logtape+logtape@2.2.4/node_modules/@logtape/logtape/dist/filter.js
|
|
1480
|
+
// node_modules/.pnpm/@logtape+logtape@2.4.2/node_modules/@logtape/logtape/dist/context.js
|
|
1009
1481
|
/**
|
|
1010
|
-
*
|
|
1482
|
+
* Internal symbol for storing category prefix in context.
|
|
1483
|
+
*/
|
|
1484
|
+
const categoryPrefixSymbol = Symbol.for("logtape.categoryPrefix");
|
|
1485
|
+
/**
|
|
1486
|
+
* Gets the current category prefix from context local storage.
|
|
1487
|
+
* @returns The current category prefix, or an empty array if not set.
|
|
1488
|
+
* @since 1.3.0
|
|
1489
|
+
*/
|
|
1490
|
+
function getCategoryPrefix() {
|
|
1491
|
+
const store = LoggerImpl.getLogger().contextLocalStorage?.getStore();
|
|
1492
|
+
if (store == null) return [];
|
|
1493
|
+
const prefix = store[categoryPrefixSymbol];
|
|
1494
|
+
return Array.isArray(prefix) ? prefix : [];
|
|
1495
|
+
}
|
|
1496
|
+
/**
|
|
1497
|
+
* Gets the current implicit context only when user-visible context keys exist.
|
|
1011
1498
|
*
|
|
1012
|
-
*
|
|
1013
|
-
*
|
|
1499
|
+
* This is intentionally not exported from the public entry point. Hot logging
|
|
1500
|
+
* paths use it to avoid allocating a fresh `{}` when no implicit context is
|
|
1501
|
+
* active, while `getImplicitContext()` keeps its public return contract.
|
|
1502
|
+
* @returns The current implicit context without internal symbol keys, or
|
|
1503
|
+
* `undefined` if there is no user-visible implicit context.
|
|
1014
1504
|
*/
|
|
1015
|
-
function
|
|
1016
|
-
|
|
1017
|
-
|
|
1505
|
+
function getImplicitContextIfAny() {
|
|
1506
|
+
const store = LoggerImpl.getLogger().contextLocalStorage?.getStore();
|
|
1507
|
+
if (store == null) return void 0;
|
|
1508
|
+
const keys = Object.keys(store);
|
|
1509
|
+
if (keys.length < 1) return void 0;
|
|
1510
|
+
const result = {};
|
|
1511
|
+
for (const key of keys) result[key] = store[key];
|
|
1512
|
+
return result;
|
|
1018
1513
|
}
|
|
1514
|
+
// node_modules/.pnpm/@logtape+logtape@2.4.2/node_modules/@logtape/logtape/dist/sanitize.js
|
|
1019
1515
|
/**
|
|
1020
|
-
*
|
|
1516
|
+
* The escape sequence emitted in place of a neutralized character.
|
|
1517
|
+
*/
|
|
1518
|
+
function escapeChar(charCode) {
|
|
1519
|
+
if (charCode === 10) return "\\n";
|
|
1520
|
+
if (charCode === 13) return "\\r";
|
|
1521
|
+
if (charCode === 27) return "\\x1b";
|
|
1522
|
+
return `\\x${charCode.toString(16).padStart(2, "0")}`;
|
|
1523
|
+
}
|
|
1524
|
+
/**
|
|
1525
|
+
* Whether a character needs escaping on its own, ignoring ESC, which is
|
|
1526
|
+
* handled separately because it may introduce a sequence worth preserving.
|
|
1527
|
+
*/
|
|
1528
|
+
function isDangerous(charCode, escapeNewlines) {
|
|
1529
|
+
if (charCode === 9) return false;
|
|
1530
|
+
if (charCode === 10 || charCode === 13) return escapeNewlines;
|
|
1531
|
+
if (charCode < 32 || charCode === 127) return true;
|
|
1532
|
+
return charCode >= 128 && charCode <= 159;
|
|
1533
|
+
}
|
|
1534
|
+
/**
|
|
1535
|
+
* Matches an SGR sequence anchored at the current position: CSI, its
|
|
1536
|
+
* parameter bytes, then the final byte `m`.
|
|
1537
|
+
*/
|
|
1538
|
+
const sgrPattern = /^\x1b\[([0-9;:]*)m/;
|
|
1539
|
+
/**
|
|
1540
|
+
* The SGR sequence that clears every attribute.
|
|
1541
|
+
*/
|
|
1542
|
+
const sgrReset = "\x1B[0m";
|
|
1543
|
+
/**
|
|
1544
|
+
* Escapes control characters and ANSI escape sequences that would otherwise be
|
|
1545
|
+
* interpreted by a terminal or by a line-oriented log reader.
|
|
1546
|
+
*
|
|
1547
|
+
* A preserved SGR sequence that is left open is closed with `` `\x1b[0m` `` at
|
|
1548
|
+
* the end of the text, so that styling an attacker sets cannot carry over into
|
|
1549
|
+
* whatever is printed next.
|
|
1550
|
+
*
|
|
1551
|
+
* ESC itself is escaped rather than the whole sequence it introduces: once the
|
|
1552
|
+
* introducer is gone, the remaining bytes (`` `[2J` ``, for instance) render as
|
|
1553
|
+
* ordinary text, so no sequence needs to be parsed to its end. The 8-bit C1
|
|
1554
|
+
* introducers (U+0080–U+009F) are escaped unconditionally, since none of them
|
|
1555
|
+
* is printable and each is a single code point with no sequence to inspect.
|
|
1556
|
+
*
|
|
1557
|
+
* @param text The text to neutralize.
|
|
1558
|
+
* @param options Which classes of characters to preserve.
|
|
1559
|
+
* @returns The neutralized text.
|
|
1560
|
+
* @since 2.0.23
|
|
1561
|
+
*/
|
|
1562
|
+
function sanitizeControlSequences(text, options = {}) {
|
|
1563
|
+
const preserveSgr = options.sgr !== "escape";
|
|
1564
|
+
const escapeNewlines = options.newlines === "escape";
|
|
1565
|
+
let needsWork = false;
|
|
1566
|
+
for (let i$1 = 0; i$1 < text.length; i$1++) {
|
|
1567
|
+
const charCode = text.charCodeAt(i$1);
|
|
1568
|
+
if (charCode === 27 || isDangerous(charCode, escapeNewlines)) {
|
|
1569
|
+
needsWork = true;
|
|
1570
|
+
break;
|
|
1571
|
+
}
|
|
1572
|
+
}
|
|
1573
|
+
if (!needsWork) return text;
|
|
1574
|
+
let result = "";
|
|
1575
|
+
let i = 0;
|
|
1576
|
+
let sgrOpen = false;
|
|
1577
|
+
while (i < text.length) {
|
|
1578
|
+
const charCode = text.charCodeAt(i);
|
|
1579
|
+
if (charCode === 27) {
|
|
1580
|
+
if (preserveSgr) {
|
|
1581
|
+
const sgr = sgrPattern.exec(text.slice(i));
|
|
1582
|
+
if (sgr != null) {
|
|
1583
|
+
result += sgr[0];
|
|
1584
|
+
sgrOpen = !isSgrReset(sgr[1]);
|
|
1585
|
+
i += sgr[0].length;
|
|
1586
|
+
continue;
|
|
1587
|
+
}
|
|
1588
|
+
}
|
|
1589
|
+
result += escapeChar(27);
|
|
1590
|
+
i++;
|
|
1591
|
+
} else if (isDangerous(charCode, escapeNewlines)) {
|
|
1592
|
+
result += escapeChar(charCode);
|
|
1593
|
+
i++;
|
|
1594
|
+
} else {
|
|
1595
|
+
result += text[i];
|
|
1596
|
+
i++;
|
|
1597
|
+
}
|
|
1598
|
+
}
|
|
1599
|
+
return sgrOpen ? result + sgrReset : result;
|
|
1600
|
+
}
|
|
1601
|
+
/**
|
|
1602
|
+
* Whether an SGR sequence's parameters clear every attribute rather than set
|
|
1603
|
+
* one. `` `\x1b[m` ``, `` `\x1b[0m` ``, and `` `\x1b[0;0m` `` all do.
|
|
1604
|
+
*/
|
|
1605
|
+
function isSgrReset(parameters) {
|
|
1606
|
+
return /^0*$/.test(parameters.replace(/[;:]/g, ""));
|
|
1607
|
+
}
|
|
1608
|
+
/**
|
|
1609
|
+
* Builds the sanitizer a formatter applies to its message and category parts.
|
|
1021
1610
|
*
|
|
1022
|
-
* @param
|
|
1023
|
-
*
|
|
1024
|
-
* @returns
|
|
1611
|
+
* @param options `false` to disable sanitization entirely, or the classes of
|
|
1612
|
+
* characters to preserve.
|
|
1613
|
+
* @returns A function that neutralizes a string, or `null` when sanitization
|
|
1614
|
+
* is disabled.
|
|
1615
|
+
* @since 2.0.23
|
|
1025
1616
|
*/
|
|
1026
|
-
function
|
|
1027
|
-
if (
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1617
|
+
function getSanitizer(options) {
|
|
1618
|
+
if (options === false) return null;
|
|
1619
|
+
const resolved = options ?? {};
|
|
1620
|
+
return (text) => sanitizeControlSequences(text, resolved);
|
|
1621
|
+
}
|
|
1622
|
+
// node_modules/.pnpm/@logtape+logtape@2.4.2/node_modules/@logtape/logtape/dist/circular.js
|
|
1623
|
+
/**
|
|
1624
|
+
* Creates a {@link JSON.stringify} replacer which renders circular references
|
|
1625
|
+
* as the string `"[Circular]"` instead of letting {@link JSON.stringify} throw
|
|
1626
|
+
* a `TypeError`.
|
|
1627
|
+
*
|
|
1628
|
+
* The returned replacer keeps a stack of the values which are currently being
|
|
1629
|
+
* serialized, so a value that merely appears more than once, such as the same
|
|
1630
|
+
* object held by two sibling properties, is still serialized in full. Only a
|
|
1631
|
+
* value which contains itself is replaced.
|
|
1632
|
+
*
|
|
1633
|
+
* The replacer is stateful; create a new one for every {@link JSON.stringify}
|
|
1634
|
+
* call.
|
|
1635
|
+
*
|
|
1636
|
+
* Cycles are detected as the replacer sees them, which is *after* a `toJSON()`
|
|
1637
|
+
* method has run. A `toJSON()` method which allocates a fresh object referring
|
|
1638
|
+
* back to its owner on every call therefore still recurses without bound, just
|
|
1639
|
+
* as it does with a plain {@link JSON.stringify} call.
|
|
1640
|
+
*
|
|
1641
|
+
* @param inner An optional replacer to compose with. It runs first, and the
|
|
1642
|
+
* value it returns is what gets serialized. Cycles are detected
|
|
1643
|
+
* in both the original and the returned values, so a replacer
|
|
1644
|
+
* which allocates a new object for every visit (as the error
|
|
1645
|
+
* serializer does) cannot hide a cycle.
|
|
1646
|
+
* @returns A replacer function to pass to {@link JSON.stringify}.
|
|
1647
|
+
*/
|
|
1648
|
+
function createCircularReplacer(inner) {
|
|
1649
|
+
const sources = [];
|
|
1650
|
+
const results = [];
|
|
1651
|
+
return function(key, value) {
|
|
1652
|
+
const result = inner === void 0 ? value : inner.call(this, key, value);
|
|
1653
|
+
if (typeof result !== "object" || result === null) return result;
|
|
1654
|
+
while (results.length > 0 && results[results.length - 1] !== this) {
|
|
1655
|
+
results.pop();
|
|
1656
|
+
sources.pop();
|
|
1657
|
+
}
|
|
1658
|
+
for (let i = 0; i < results.length; i++) if (results[i] === result || sources[i] === value) return "[Circular]";
|
|
1659
|
+
sources.push(value);
|
|
1660
|
+
results.push(result);
|
|
1661
|
+
return result;
|
|
1662
|
+
};
|
|
1035
1663
|
}
|
|
1036
|
-
|
|
1037
|
-
|
|
1664
|
+
/**
|
|
1665
|
+
* Serializes a value the way {@link JSON.stringify} does, except that circular
|
|
1666
|
+
* references are rendered as the string `"[Circular]"` instead of throwing
|
|
1667
|
+
* a `TypeError`.
|
|
1668
|
+
*
|
|
1669
|
+
* The plain {@link JSON.stringify} call is attempted first and the cycle-safe
|
|
1670
|
+
* replacer is installed only if it throws, so values without cycles (by far the
|
|
1671
|
+
* common case) cost exactly what they cost before. The price is that a value
|
|
1672
|
+
* which does contain a cycle is traversed twice, so its getters and `toJSON()`
|
|
1673
|
+
* methods run twice. If the second attempt fails as well, its error is thrown;
|
|
1674
|
+
* values {@link JSON.stringify} cannot serialize at all, such as `BigInt`s,
|
|
1675
|
+
* therefore keep failing as before.
|
|
1676
|
+
*
|
|
1677
|
+
* Like {@link JSON.stringify}, this returns `undefined` rather than a string
|
|
1678
|
+
* for `undefined`, functions, and symbols. The return type says so, unlike
|
|
1679
|
+
* the built-in's own declaration, so that every caller has to pick its own
|
|
1680
|
+
* fallback for those values.
|
|
1681
|
+
*
|
|
1682
|
+
* @param value The value to serialize.
|
|
1683
|
+
* @param replacer An optional replacer to apply, as in {@link JSON.stringify}.
|
|
1684
|
+
* @param space An optional indentation, as in {@link JSON.stringify}.
|
|
1685
|
+
* @returns The JSON representation of the value.
|
|
1686
|
+
*/
|
|
1687
|
+
function stringifyWithoutCycles(value, replacer, space) {
|
|
1688
|
+
try {
|
|
1689
|
+
return JSON.stringify(value, replacer, space);
|
|
1690
|
+
} catch {
|
|
1691
|
+
return JSON.stringify(value, createCircularReplacer(replacer), space);
|
|
1692
|
+
}
|
|
1693
|
+
}
|
|
1694
|
+
// node_modules/.pnpm/@logtape+logtape@2.4.2/node_modules/@logtape/logtape/dist/util.js
|
|
1038
1695
|
var util_exports = /* @__PURE__ */ __exportAll({ inspect: () => inspect$1 });
|
|
1039
1696
|
function inspect$1(obj, options) {
|
|
1040
|
-
|
|
1041
|
-
return JSON.stringify(obj, null, indent);
|
|
1697
|
+
return stringifyWithoutCycles(obj, void 0, options?.compact === true ? void 0 : 2) ?? "undefined";
|
|
1042
1698
|
}
|
|
1043
|
-
|
|
1044
|
-
//#region node_modules/.pnpm/@logtape+logtape@2.2.4/node_modules/@logtape/logtape/dist/formatter.js
|
|
1699
|
+
// node_modules/.pnpm/@logtape+logtape@2.4.2/node_modules/@logtape/logtape/dist/formatter.js
|
|
1045
1700
|
/**
|
|
1046
1701
|
* The severity level abbreviations.
|
|
1047
1702
|
*/
|
|
@@ -1056,34 +1711,59 @@ const levelAbbreviations = {
|
|
|
1056
1711
|
/**
|
|
1057
1712
|
* A platform-specific inspect function. In Deno, this is {@link Deno.inspect},
|
|
1058
1713
|
* and in Node.js/Bun it is `util.inspect()`. If neither is available, it
|
|
1059
|
-
* falls back to
|
|
1714
|
+
* falls back to JSON serialization, which renders circular references as
|
|
1715
|
+
* `"[Circular]"` rather than throwing.
|
|
1060
1716
|
*
|
|
1061
1717
|
* @param value The value to inspect.
|
|
1062
1718
|
* @param options The options for inspecting the value.
|
|
1063
1719
|
* If `colors` is `true`, the output will be ANSI-colored.
|
|
1064
1720
|
* @returns The string representation of the value.
|
|
1065
1721
|
*/
|
|
1066
|
-
const platformInspect = typeof document !== "undefined" || typeof navigator !== "undefined" && navigator.product === "ReactNative" ? (v) =>
|
|
1067
|
-
strAbbreviateSize:
|
|
1068
|
-
iterableLimit:
|
|
1722
|
+
const platformInspect = typeof document !== "undefined" || typeof navigator !== "undefined" && navigator.product === "ReactNative" ? (v) => stringifyWithoutCycles(v) : "Deno" in globalThis && "inspect" in globalThis.Deno && typeof globalThis.Deno.inspect === "function" ? (v, opts) => globalThis.Deno.inspect(v, {
|
|
1723
|
+
strAbbreviateSize: 1e400,
|
|
1724
|
+
iterableLimit: 1e400,
|
|
1069
1725
|
...opts
|
|
1070
|
-
}) : util_exports != null &&
|
|
1071
|
-
maxArrayLength:
|
|
1072
|
-
maxStringLength:
|
|
1726
|
+
}) : util_exports != null && typeof inspect$1 === "function" ? (v, opts) => inspect$1(v, {
|
|
1727
|
+
maxArrayLength: 1e400,
|
|
1728
|
+
maxStringLength: 1e400,
|
|
1073
1729
|
...opts
|
|
1074
|
-
}) : (v) =>
|
|
1730
|
+
}) : (v) => stringifyWithoutCycles(v);
|
|
1075
1731
|
const inspect = (value, options) => String(platformInspect(value, options));
|
|
1076
1732
|
const utf8Encoder = new TextEncoder();
|
|
1077
|
-
|
|
1733
|
+
/**
|
|
1734
|
+
* Builds the function that renders the values interpolated into a message
|
|
1735
|
+
* from {@link TextFormatterOptions.value}.
|
|
1736
|
+
*
|
|
1737
|
+
* @param value The `value` option.
|
|
1738
|
+
* @param sanitize The `sanitize` option, which also governs how strings are
|
|
1739
|
+
* neutralized under the `"bare"` preset.
|
|
1740
|
+
* @param fallback Renders the values that the option leaves to the default,
|
|
1741
|
+
* i.e., every value when the option is omitted, and every
|
|
1742
|
+
* non-string value under the `"bare"` preset.
|
|
1743
|
+
* @returns The value renderer.
|
|
1744
|
+
* @throws {TypeError} If the option is neither `"bare"` nor a function.
|
|
1745
|
+
*/
|
|
1746
|
+
function getValueRenderer(value, sanitize, fallback) {
|
|
1747
|
+
if (value == null) return fallback;
|
|
1748
|
+
if (typeof value === "function") return (v) => value(v, inspect);
|
|
1749
|
+
if (value !== "bare") throw new TypeError(`Invalid value option: ${JSON.stringify(value)}. It must be "bare" or a function.`);
|
|
1750
|
+
const sanitizeBare = sanitize === false ? null : getSanitizer({
|
|
1751
|
+
sgr: "escape",
|
|
1752
|
+
newlines: sanitize?.newlines ?? "escape"
|
|
1753
|
+
});
|
|
1754
|
+
return sanitizeBare == null ? (v) => typeof v === "string" ? v : fallback(v) : (v) => typeof v === "string" ? sanitizeBare(v) : fallback(v);
|
|
1755
|
+
}
|
|
1756
|
+
function renderMessageParts(msgParts, valueRenderer, sanitize) {
|
|
1078
1757
|
const msgLen = msgParts.length;
|
|
1079
|
-
|
|
1758
|
+
const renderPart = sanitize == null ? (part) => part : (part) => sanitize(part);
|
|
1759
|
+
if (msgLen === 1) return renderPart(msgParts[0]);
|
|
1080
1760
|
if (msgLen <= 6) {
|
|
1081
1761
|
let message = "";
|
|
1082
|
-
for (let i = 0; i < msgLen; i++) message += i % 2 === 0 ? msgParts[i] : valueRenderer(msgParts[i]);
|
|
1762
|
+
for (let i = 0; i < msgLen; i++) message += i % 2 === 0 ? renderPart(msgParts[i]) : valueRenderer(msgParts[i]);
|
|
1083
1763
|
return message;
|
|
1084
1764
|
}
|
|
1085
1765
|
const parts = new Array(msgLen);
|
|
1086
|
-
for (let i = 0; i < msgLen; i++) parts[i] = i % 2 === 0 ? msgParts[i] : valueRenderer(msgParts[i]);
|
|
1766
|
+
for (let i = 0; i < msgLen; i++) parts[i] = i % 2 === 0 ? renderPart(msgParts[i]) : valueRenderer(msgParts[i]);
|
|
1087
1767
|
return parts.join("");
|
|
1088
1768
|
}
|
|
1089
1769
|
function padZero(num) {
|
|
@@ -1272,7 +1952,31 @@ const levelRenderersCache = {
|
|
|
1272
1952
|
function getLineEndingValue(lineEnding) {
|
|
1273
1953
|
return lineEnding === "crlf" ? "\r\n" : "\n";
|
|
1274
1954
|
}
|
|
1955
|
+
/**
|
|
1956
|
+
* Escapes the characters that {@link JSON.stringify} leaves as raw code points
|
|
1957
|
+
* but that a terminal reads as control codes: DEL and the C1 range
|
|
1958
|
+
* (U+0080–U+009F), whose members include the 8-bit `CSI` and `OSC`
|
|
1959
|
+
* introducers.
|
|
1960
|
+
*
|
|
1961
|
+
* The replacement is a JSON `\uXXXX` escape rather than the text formatters'
|
|
1962
|
+
* `` `\xNN` `` spelling, so the value survives {@link JSON.parse} unchanged.
|
|
1963
|
+
* Applying it to a whole serialized line is safe because every structural
|
|
1964
|
+
* character of JSON is ASCII, so a code point in this range can only ever be
|
|
1965
|
+
* literal data inside a string.
|
|
1966
|
+
*/
|
|
1967
|
+
const jsonControlPattern = /[\u007f-\u009f]/g;
|
|
1968
|
+
function escapeJsonControlChars(json) {
|
|
1969
|
+
return json.replace(jsonControlPattern, (char) => `\\u${char.charCodeAt(0).toString(16).padStart(4, "0")}`);
|
|
1970
|
+
}
|
|
1971
|
+
function bigintReplacer(_key, value) {
|
|
1972
|
+
return typeof value === "bigint" ? value.toString() : value;
|
|
1973
|
+
}
|
|
1974
|
+
function stringifyJsonMessageValue(value) {
|
|
1975
|
+
if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") return JSON.stringify(value);
|
|
1976
|
+
return stringifyWithoutCycles(value, bigintReplacer);
|
|
1977
|
+
}
|
|
1275
1978
|
function jsonReplacer(_key, value) {
|
|
1979
|
+
if (typeof value === "bigint") return value.toString();
|
|
1276
1980
|
if (!(value instanceof Error)) return value;
|
|
1277
1981
|
const serialized = {
|
|
1278
1982
|
name: value.name,
|
|
@@ -1288,9 +1992,9 @@ function jsonReplacer(_key, value) {
|
|
|
1288
1992
|
function renderDefaultJsonLinesMessage(message) {
|
|
1289
1993
|
const messageLength = message.length;
|
|
1290
1994
|
if (messageLength === 1) return message[0];
|
|
1291
|
-
if (messageLength === 3) return message[0] +
|
|
1995
|
+
if (messageLength === 3) return message[0] + stringifyJsonMessageValue(message[1]) + message[2];
|
|
1292
1996
|
let rendered = message[0];
|
|
1293
|
-
for (let i = 1; i < messageLength; i++) rendered += i & 1 ?
|
|
1997
|
+
for (let i = 1; i < messageLength; i++) rendered += i & 1 ? stringifyJsonMessageValue(message[i]) : message[i];
|
|
1294
1998
|
return rendered;
|
|
1295
1999
|
}
|
|
1296
2000
|
function stringifyJsonLinesField(key, value) {
|
|
@@ -1298,7 +2002,7 @@ function stringifyJsonLinesField(key, value) {
|
|
|
1298
2002
|
const toJSON = value.toJSON;
|
|
1299
2003
|
if (typeof toJSON === "function") value = toJSON.call(value, key);
|
|
1300
2004
|
}
|
|
1301
|
-
return JSON.stringify(jsonReplacer(key, value), jsonReplacer);
|
|
2005
|
+
return JSON.stringify(jsonReplacer(key, value), createCircularReplacer(jsonReplacer));
|
|
1302
2006
|
}
|
|
1303
2007
|
function formatDefaultJsonLinesRecord(record, lineEnding) {
|
|
1304
2008
|
const level = record.level === "warning" ? "WARN" : record.level.toUpperCase();
|
|
@@ -1308,7 +2012,7 @@ function formatDefaultJsonLinesRecord(record, lineEnding) {
|
|
|
1308
2012
|
if (messageJson !== void 0) line += `,"message":${messageJson}`;
|
|
1309
2013
|
line += `,"logger":${JSON.stringify(record.category.join("."))}`;
|
|
1310
2014
|
if (propertiesJson !== void 0) line += `,"properties":${propertiesJson}`;
|
|
1311
|
-
return `${line}}
|
|
2015
|
+
return escapeJsonControlChars(`${line}}`) + lineEnding;
|
|
1312
2016
|
}
|
|
1313
2017
|
/**
|
|
1314
2018
|
* Get a text formatter with the specified options. Although it's flexible
|
|
@@ -1337,7 +2041,12 @@ function getTextFormatter(options = {}) {
|
|
|
1337
2041
|
else return tsOption;
|
|
1338
2042
|
})();
|
|
1339
2043
|
const categorySeparator = options.category ?? "·";
|
|
1340
|
-
const
|
|
2044
|
+
const sanitize = getSanitizer(options.sanitize);
|
|
2045
|
+
const sanitizeCategory = getSanitizer(options.sanitize === false ? false : {
|
|
2046
|
+
...options.sanitize,
|
|
2047
|
+
sgr: "escape"
|
|
2048
|
+
});
|
|
2049
|
+
const valueRenderer = getValueRenderer(options.value, options.sanitize, inspect);
|
|
1341
2050
|
const levelRenderer = (() => {
|
|
1342
2051
|
const levelOption = options.level;
|
|
1343
2052
|
if (levelOption == null || levelOption === "ABBR") return (level) => levelRenderersCache.ABBR[level];
|
|
@@ -1349,18 +2058,42 @@ function getTextFormatter(options = {}) {
|
|
|
1349
2058
|
else return levelOption;
|
|
1350
2059
|
})();
|
|
1351
2060
|
const lineEnding = getLineEndingValue(options.lineEnding);
|
|
1352
|
-
const
|
|
2061
|
+
const sourceLocationRenderer = getSourceLocationRenderer(options.sourceLocation, options.sanitize === false ? null : getSanitizer({
|
|
2062
|
+
...options.sanitize,
|
|
2063
|
+
sgr: "escape",
|
|
2064
|
+
newlines: "escape"
|
|
2065
|
+
}));
|
|
2066
|
+
const formatter = options.format ?? (({ timestamp, level, category, message, sourceLocation }) => `${timestamp ? `${timestamp} ` : ""}[${level}] ${category}${sourceLocation == null ? "" : ` (${sourceLocation})`}: ${message}`);
|
|
1353
2067
|
return (record) => {
|
|
1354
|
-
const message = renderMessageParts(record.message, valueRenderer);
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
2068
|
+
const message = renderMessageParts(record.message, valueRenderer, sanitize);
|
|
2069
|
+
const timestamp = timestampRenderer(record.timestamp);
|
|
2070
|
+
const level = levelRenderer(record.level);
|
|
2071
|
+
const categoryParts = sanitizeCategory == null ? record.category : record.category.map(sanitizeCategory);
|
|
2072
|
+
const values = {
|
|
2073
|
+
timestamp,
|
|
2074
|
+
level,
|
|
2075
|
+
category: typeof categorySeparator === "function" ? categorySeparator(categoryParts) : categoryParts.join(categorySeparator),
|
|
1359
2076
|
message,
|
|
1360
2077
|
record
|
|
1361
|
-
}
|
|
2078
|
+
};
|
|
2079
|
+
if (sourceLocationRenderer != null) values.sourceLocation = record.sourceLocation == null ? null : sourceLocationRenderer(record.sourceLocation);
|
|
2080
|
+
return `${formatter(values)}${lineEnding}`;
|
|
1362
2081
|
};
|
|
1363
2082
|
}
|
|
2083
|
+
/**
|
|
2084
|
+
* Builds the function that renders source locations for the
|
|
2085
|
+
* `sourceLocation` option of a formatter.
|
|
2086
|
+
* @param option The `sourceLocation` option.
|
|
2087
|
+
* @param sanitize The function to escape control characters in the rendered
|
|
2088
|
+
* location, if any.
|
|
2089
|
+
* @returns The renderer, or `null` if source locations are not shown.
|
|
2090
|
+
*/
|
|
2091
|
+
function getSourceLocationRenderer(option, sanitize) {
|
|
2092
|
+
if (option == null || option === false) return null;
|
|
2093
|
+
const render = option === true ? (location) => `${location.file}:${location.line}:${location.column}` : option;
|
|
2094
|
+
if (sanitize == null) return render;
|
|
2095
|
+
return (location) => sanitize(render(location));
|
|
2096
|
+
}
|
|
1364
2097
|
getTextFormatter();
|
|
1365
2098
|
const RESET = "\x1B[0m";
|
|
1366
2099
|
const ansiColors = {
|
|
@@ -1414,17 +2147,21 @@ function getAnsiColorFormatter(options = {}) {
|
|
|
1414
2147
|
return fallbackInspect(value, { colors: true });
|
|
1415
2148
|
},
|
|
1416
2149
|
...options,
|
|
1417
|
-
|
|
2150
|
+
...options.value === "bare" ? { value: getValueRenderer("bare", options.sanitize, (v) => inspect(v, { colors: true })) } : {},
|
|
2151
|
+
format({ timestamp, level, category, message, sourceLocation, record }) {
|
|
1418
2152
|
const levelColor = levelColors[record.level];
|
|
1419
2153
|
timestamp = timestamp == null ? null : `${timestampPrefix}${timestamp}${timestampSuffix}`;
|
|
1420
2154
|
level = `${levelStyle == null ? "" : ansiStyles[levelStyle]}${levelColor == null ? "" : ansiColors[levelColor]}${level}${levelStyle == null && levelColor == null ? "" : RESET}`;
|
|
1421
|
-
|
|
2155
|
+
if (format == null) return `${timestamp == null ? "" : `${timestamp} `}${level} ${categoryPrefix}${category}${sourceLocation == null ? "" : ` (${sourceLocation})`}:${categorySuffix} ${message}`;
|
|
2156
|
+
const values = {
|
|
1422
2157
|
timestamp,
|
|
1423
2158
|
level,
|
|
1424
2159
|
category: `${categoryPrefix}${category}${categorySuffix}`,
|
|
1425
2160
|
message,
|
|
1426
2161
|
record
|
|
1427
|
-
}
|
|
2162
|
+
};
|
|
2163
|
+
if (sourceLocation !== void 0) values.sourceLocation = sourceLocation == null ? null : `${categoryPrefix}${sourceLocation}${categorySuffix}`;
|
|
2164
|
+
return format(values);
|
|
1428
2165
|
}
|
|
1429
2166
|
});
|
|
1430
2167
|
}
|
|
@@ -1433,6 +2170,8 @@ getAnsiColorFormatter();
|
|
|
1433
2170
|
* Get a [JSON Lines] formatter with the specified options. The log records
|
|
1434
2171
|
* will be rendered as JSON objects, one per line, which is a common format
|
|
1435
2172
|
* for log files. This format is also known as Newline-Delimited JSON (NDJSON).
|
|
2173
|
+
* Bigint values in properties and interpolated messages are serialized as
|
|
2174
|
+
* decimal strings to preserve precision.
|
|
1436
2175
|
* It looks like this:
|
|
1437
2176
|
*
|
|
1438
2177
|
* ```json
|
|
@@ -1483,17 +2222,17 @@ function getJsonLinesFormatter(options = {}) {
|
|
|
1483
2222
|
const msgLen = record.message.length;
|
|
1484
2223
|
if (msgLen === 1) return record.message[0];
|
|
1485
2224
|
let msg = "";
|
|
1486
|
-
for (let i = 0; i < msgLen; i++) msg += i % 2 < 1 ? record.message[i] :
|
|
2225
|
+
for (let i = 0; i < msgLen; i++) msg += i % 2 < 1 ? record.message[i] : stringifyJsonMessageValue(record.message[i]);
|
|
1487
2226
|
return msg;
|
|
1488
2227
|
};
|
|
1489
2228
|
return (record) => {
|
|
1490
|
-
return JSON.stringify({
|
|
2229
|
+
return escapeJsonControlChars(JSON.stringify({
|
|
1491
2230
|
"@timestamp": new Date(record.timestamp).toISOString(),
|
|
1492
2231
|
level: record.level === "warning" ? "WARN" : record.level.toUpperCase(),
|
|
1493
2232
|
message: getMessage(record),
|
|
1494
2233
|
logger: joinCategory(record.category),
|
|
1495
2234
|
...getProperties(record.properties)
|
|
1496
|
-
}, jsonReplacer) + lineEnding;
|
|
2235
|
+
}, createCircularReplacer(jsonReplacer))) + lineEnding;
|
|
1497
2236
|
};
|
|
1498
2237
|
}
|
|
1499
2238
|
getJsonLinesFormatter();
|
|
@@ -1517,8 +2256,16 @@ function filterLogfmtKey(key) {
|
|
|
1517
2256
|
else result += char;
|
|
1518
2257
|
return result;
|
|
1519
2258
|
}
|
|
2259
|
+
/**
|
|
2260
|
+
* Whether a code point is one that a terminal reads as a control code even
|
|
2261
|
+
* though it is not a C0 control: DEL and the C1 range (U+0080–U+009F),
|
|
2262
|
+
* whose members include the 8-bit `CSI` and `OSC` introducers.
|
|
2263
|
+
*/
|
|
2264
|
+
function isTerminalControlCode(code) {
|
|
2265
|
+
return code === 127 || code >= 128 && code <= 159;
|
|
2266
|
+
}
|
|
1520
2267
|
function shouldEscapeLogfmtKeyChar(char, code) {
|
|
1521
|
-
return code <= 32 || code
|
|
2268
|
+
return code <= 32 || isTerminalControlCode(code) || code === 65533 || char === "=" || char === "\"" || char === "%";
|
|
1522
2269
|
}
|
|
1523
2270
|
function encodeLogfmtKeyChar(char) {
|
|
1524
2271
|
let result = "";
|
|
@@ -1557,7 +2304,7 @@ function shouldQuoteStringLiteral(value) {
|
|
|
1557
2304
|
return value === "null" || value === "undefined" || value === "true" || value === "false";
|
|
1558
2305
|
}
|
|
1559
2306
|
function shouldQuoteLogfmtValueChar(char, code) {
|
|
1560
|
-
return code <= 32 || code
|
|
2307
|
+
return code <= 32 || isTerminalControlCode(code) || code === 65533 || char === "=" || char === "\"" || char === "\\";
|
|
1561
2308
|
}
|
|
1562
2309
|
function escapeLogfmtValueChar(char, code) {
|
|
1563
2310
|
switch (char) {
|
|
@@ -1566,7 +2313,7 @@ function escapeLogfmtValueChar(char, code) {
|
|
|
1566
2313
|
case "\r": return "\\r";
|
|
1567
2314
|
case "\"": return "\\\"";
|
|
1568
2315
|
case "\\": return "\\\\";
|
|
1569
|
-
default: return code <= 31 || code
|
|
2316
|
+
default: return code <= 31 || isTerminalControlCode(code) ? `\\u${code.toString(16).padStart(4, "0")}` : char;
|
|
1570
2317
|
}
|
|
1571
2318
|
}
|
|
1572
2319
|
function formatLogfmtValue(value) {
|
|
@@ -1639,26 +2386,92 @@ const logLevelStyles = {
|
|
|
1639
2386
|
* {@link console.log}.
|
|
1640
2387
|
*/
|
|
1641
2388
|
function defaultConsoleFormatter(record) {
|
|
2389
|
+
return formatConsoleRecord(record, void 0);
|
|
2390
|
+
}
|
|
2391
|
+
function formatConsoleRecord(record, sourceLocation) {
|
|
1642
2392
|
let msg = "";
|
|
1643
2393
|
const values = [];
|
|
1644
|
-
for (let i = 0; i < record.message.length; i++) if (i % 2 === 0) msg += record.message[i];
|
|
2394
|
+
for (let i = 0; i < record.message.length; i++) if (i % 2 === 0) msg += sanitizeControlSequences(record.message[i]);
|
|
1645
2395
|
else {
|
|
1646
2396
|
msg += "%o";
|
|
1647
2397
|
values.push(record.message[i]);
|
|
1648
2398
|
}
|
|
1649
2399
|
const date = new Date(record.timestamp);
|
|
2400
|
+
const time = `${date.getUTCHours().toString().padStart(2, "0")}:${date.getUTCMinutes().toString().padStart(2, "0")}:${date.getUTCSeconds().toString().padStart(2, "0")}.${date.getUTCMilliseconds().toString().padStart(3, "0")}`;
|
|
2401
|
+
const category = record.category.map((c) => sanitizeControlSequences(c, { sgr: "escape" })).join("·");
|
|
2402
|
+
if (sourceLocation == null) return [
|
|
2403
|
+
`%c${time} %c${levelAbbreviations[record.level]}%c %c${category} %c${msg}`,
|
|
2404
|
+
"color: gray;",
|
|
2405
|
+
logLevelStyles[record.level],
|
|
2406
|
+
"background-color: default;",
|
|
2407
|
+
"color: gray;",
|
|
2408
|
+
"color: default;",
|
|
2409
|
+
...values
|
|
2410
|
+
];
|
|
1650
2411
|
return [
|
|
1651
|
-
`%c${
|
|
2412
|
+
`%c${time} %c${levelAbbreviations[record.level]}%c %c${category} (%s) %c${msg}`,
|
|
1652
2413
|
"color: gray;",
|
|
1653
2414
|
logLevelStyles[record.level],
|
|
1654
2415
|
"background-color: default;",
|
|
1655
2416
|
"color: gray;",
|
|
2417
|
+
sourceLocation,
|
|
1656
2418
|
"color: default;",
|
|
1657
2419
|
...values
|
|
1658
2420
|
];
|
|
1659
2421
|
}
|
|
1660
|
-
|
|
1661
|
-
|
|
2422
|
+
// node_modules/.pnpm/@logtape+logtape@2.4.2/node_modules/@logtape/logtape/dist/sink.js
|
|
2423
|
+
function createSinkNotifications(sink, interval, onDrop, onError) {
|
|
2424
|
+
let notificationDepth = 0;
|
|
2425
|
+
let dropped = 0;
|
|
2426
|
+
let timer = null;
|
|
2427
|
+
function notify(callback, event) {
|
|
2428
|
+
notificationDepth++;
|
|
2429
|
+
try {
|
|
2430
|
+
const result = callback(event);
|
|
2431
|
+
if (result != null) Promise.resolve(result).catch(() => {});
|
|
2432
|
+
} catch {} finally {
|
|
2433
|
+
notificationDepth--;
|
|
2434
|
+
}
|
|
2435
|
+
}
|
|
2436
|
+
function reportDrops() {
|
|
2437
|
+
const count = dropped;
|
|
2438
|
+
dropped = 0;
|
|
2439
|
+
if (count > 0 && onDrop != null) notify(onDrop, {
|
|
2440
|
+
count,
|
|
2441
|
+
reason: "overflow"
|
|
2442
|
+
});
|
|
2443
|
+
}
|
|
2444
|
+
return {
|
|
2445
|
+
get notifying() {
|
|
2446
|
+
return notificationDepth > 0;
|
|
2447
|
+
},
|
|
2448
|
+
drop() {
|
|
2449
|
+
if (onDrop == null) return;
|
|
2450
|
+
dropped++;
|
|
2451
|
+
if (timer == null) timer = setTimeout(() => {
|
|
2452
|
+
timer = null;
|
|
2453
|
+
reportDrops();
|
|
2454
|
+
}, interval);
|
|
2455
|
+
},
|
|
2456
|
+
error(error, operation, defer = false) {
|
|
2457
|
+
if (onError == null) return;
|
|
2458
|
+
const event = {
|
|
2459
|
+
error,
|
|
2460
|
+
sink,
|
|
2461
|
+
operation
|
|
2462
|
+
};
|
|
2463
|
+
if (defer) queueMicrotask(() => notify(onError, event));
|
|
2464
|
+
else notify(onError, event);
|
|
2465
|
+
},
|
|
2466
|
+
dispose() {
|
|
2467
|
+
if (timer != null) {
|
|
2468
|
+
clearTimeout(timer);
|
|
2469
|
+
timer = null;
|
|
2470
|
+
}
|
|
2471
|
+
reportDrops();
|
|
2472
|
+
}
|
|
2473
|
+
};
|
|
2474
|
+
}
|
|
1662
2475
|
/**
|
|
1663
2476
|
* A console sink factory that returns a sink that logs to the console.
|
|
1664
2477
|
*
|
|
@@ -1678,8 +2491,7 @@ function getConsoleSink(options = {}) {
|
|
|
1678
2491
|
...options.levelMap ?? {}
|
|
1679
2492
|
};
|
|
1680
2493
|
const console = options.console ?? globalThis.console;
|
|
1681
|
-
const
|
|
1682
|
-
const args = formatter(record);
|
|
2494
|
+
const writeToConsole = (record, args) => {
|
|
1683
2495
|
const method = levelMap[record.level];
|
|
1684
2496
|
if (method === void 0) throw new TypeError(`Invalid log level: ${record.level}.`);
|
|
1685
2497
|
if (typeof args === "string") {
|
|
@@ -1687,10 +2499,14 @@ function getConsoleSink(options = {}) {
|
|
|
1687
2499
|
console[method](msg);
|
|
1688
2500
|
} else console[method](...args);
|
|
1689
2501
|
};
|
|
2502
|
+
const baseSink = (record) => {
|
|
2503
|
+
writeToConsole(record, formatter(record));
|
|
2504
|
+
};
|
|
1690
2505
|
if (!options.nonBlocking) return baseSink;
|
|
1691
2506
|
const nonBlockingConfig = options.nonBlocking === true ? {} : options.nonBlocking;
|
|
1692
2507
|
const bufferSize = nonBlockingConfig.bufferSize ?? 100;
|
|
1693
2508
|
const flushInterval = nonBlockingConfig.flushInterval ?? 100;
|
|
2509
|
+
const notifications = createSinkNotifications("console", flushInterval, nonBlockingConfig.onDrop, nonBlockingConfig.onError);
|
|
1694
2510
|
const buffer = [];
|
|
1695
2511
|
let flushTimer = null;
|
|
1696
2512
|
let scheduledFlushTimer = null;
|
|
@@ -1700,9 +2516,16 @@ function getConsoleSink(options = {}) {
|
|
|
1700
2516
|
function flush() {
|
|
1701
2517
|
if (buffer.length === 0) return;
|
|
1702
2518
|
const records = buffer.splice(0);
|
|
1703
|
-
for (const record of records)
|
|
1704
|
-
|
|
1705
|
-
|
|
2519
|
+
for (const record of records) {
|
|
2520
|
+
let operation = "format";
|
|
2521
|
+
try {
|
|
2522
|
+
const args = formatter(record);
|
|
2523
|
+
operation = "write";
|
|
2524
|
+
writeToConsole(record, args);
|
|
2525
|
+
} catch (error) {
|
|
2526
|
+
notifications.error(error, operation);
|
|
2527
|
+
}
|
|
2528
|
+
}
|
|
1706
2529
|
}
|
|
1707
2530
|
function scheduleFlush() {
|
|
1708
2531
|
if (flushScheduled) return;
|
|
@@ -1720,13 +2543,17 @@ function getConsoleSink(options = {}) {
|
|
|
1720
2543
|
}, flushInterval);
|
|
1721
2544
|
}
|
|
1722
2545
|
const nonBlockingSink = (record) => {
|
|
1723
|
-
if (disposed) return;
|
|
1724
|
-
if (buffer.length >= maxBufferSize
|
|
2546
|
+
if (disposed || notifications.notifying) return;
|
|
2547
|
+
if (buffer.length >= maxBufferSize && buffer.length > 0) {
|
|
2548
|
+
buffer.shift();
|
|
2549
|
+
notifications.drop();
|
|
2550
|
+
}
|
|
1725
2551
|
buffer.push(record);
|
|
1726
2552
|
if (buffer.length >= bufferSize) scheduleFlush();
|
|
1727
2553
|
else if (flushTimer === null) startFlushTimer();
|
|
1728
2554
|
};
|
|
1729
|
-
nonBlockingSink[
|
|
2555
|
+
nonBlockingSink[disposeSymbol] = () => {
|
|
2556
|
+
if (disposed) return;
|
|
1730
2557
|
disposed = true;
|
|
1731
2558
|
if (flushTimer !== null) {
|
|
1732
2559
|
clearInterval(flushTimer);
|
|
@@ -1737,16 +2564,17 @@ function getConsoleSink(options = {}) {
|
|
|
1737
2564
|
scheduledFlushTimer = null;
|
|
1738
2565
|
flushScheduled = false;
|
|
1739
2566
|
}
|
|
2567
|
+
notifications.dispose();
|
|
1740
2568
|
flush();
|
|
1741
2569
|
};
|
|
1742
2570
|
return nonBlockingSink;
|
|
1743
2571
|
}
|
|
1744
|
-
|
|
1745
|
-
//#region node_modules/.pnpm/@logtape+logtape@2.2.4/node_modules/@logtape/logtape/dist/config.js
|
|
2572
|
+
// node_modules/.pnpm/@logtape+logtape@2.4.2/node_modules/@logtape/logtape/dist/config.js
|
|
1746
2573
|
/**
|
|
1747
2574
|
* The current configuration, if any. Otherwise, `null`.
|
|
1748
2575
|
*/
|
|
1749
2576
|
let currentConfig = null;
|
|
2577
|
+
let globalConfigMutationInProgress = false;
|
|
1750
2578
|
/**
|
|
1751
2579
|
* Strong references to the loggers.
|
|
1752
2580
|
* This is to prevent the loggers from being garbage collected so that their
|
|
@@ -1754,6 +2582,24 @@ let currentConfig = null;
|
|
|
1754
2582
|
*/
|
|
1755
2583
|
const strongRefs = /* @__PURE__ */ new Set();
|
|
1756
2584
|
/**
|
|
2585
|
+
* The sinks installed by the current configuration, which {@link drain}
|
|
2586
|
+
* drains. Kept separately from {@link currentConfig} because the caller may
|
|
2587
|
+
* mutate the configuration object after configuring.
|
|
2588
|
+
*/
|
|
2589
|
+
const installedSinks = /* @__PURE__ */ new Set();
|
|
2590
|
+
const inspectionStateSymbol = Symbol.for("logtape.inspectionState");
|
|
2591
|
+
function getInspectionState() {
|
|
2592
|
+
const registry = globalThis;
|
|
2593
|
+
const state = registry[inspectionStateSymbol];
|
|
2594
|
+
if (state != null && state.loggers instanceof WeakMap) return state;
|
|
2595
|
+
const newState = {
|
|
2596
|
+
configured: false,
|
|
2597
|
+
loggers: /* @__PURE__ */ new WeakMap()
|
|
2598
|
+
};
|
|
2599
|
+
registry[inspectionStateSymbol] = newState;
|
|
2600
|
+
return newState;
|
|
2601
|
+
}
|
|
2602
|
+
/**
|
|
1757
2603
|
* Sync filter disposables to dispose when resetting the configuration.
|
|
1758
2604
|
*/
|
|
1759
2605
|
const filterDisposables = /* @__PURE__ */ new Set();
|
|
@@ -1771,6 +2617,15 @@ const asyncFilterDisposables = /* @__PURE__ */ new Set();
|
|
|
1771
2617
|
const asyncSinkDisposables = /* @__PURE__ */ new Set();
|
|
1772
2618
|
let unregisterDisposeHook;
|
|
1773
2619
|
/**
|
|
2620
|
+
* Gets the root logger to toggle source location capture on. The root logger
|
|
2621
|
+
* is shared through the global object, so it can be made by an older copy of
|
|
2622
|
+
* LogTape loaded by another package, which lacks these methods. Its loggers
|
|
2623
|
+
* never capture source locations, so the calls are just skipped then.
|
|
2624
|
+
*/
|
|
2625
|
+
function getSourceLocationRoot() {
|
|
2626
|
+
return LoggerImpl.getLogger();
|
|
2627
|
+
}
|
|
2628
|
+
/**
|
|
1774
2629
|
* Check if a config is for the meta logger.
|
|
1775
2630
|
*/
|
|
1776
2631
|
function isLoggerConfigMeta(cfg) {
|
|
@@ -1780,7 +2635,7 @@ function isLoggerConfigMeta(cfg) {
|
|
|
1780
2635
|
function registerDisposeHook(allowAsync) {
|
|
1781
2636
|
unregisterDisposeHook?.();
|
|
1782
2637
|
unregisterDisposeHook = void 0;
|
|
1783
|
-
const handler = allowAsync ?
|
|
2638
|
+
const handler = allowAsync ? disposeInternal : disposeSyncInternal;
|
|
1784
2639
|
if (typeof globalThis.EdgeRuntime !== "string" && "process" in globalThis && !("Deno" in globalThis)) {
|
|
1785
2640
|
const proc = globalThis.process;
|
|
1786
2641
|
const onMethod = proc?.["on"];
|
|
@@ -1848,18 +2703,26 @@ function registerDisposeHook(allowAsync) {
|
|
|
1848
2703
|
* @param config The configuration.
|
|
1849
2704
|
*/
|
|
1850
2705
|
async function configure(config) {
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
2706
|
+
await runGlobalConfigMutation("configure()", async () => {
|
|
2707
|
+
if (currentConfig != null && !config.reset) throw new ConfigError("Already configured; if you want to reset, turn on the reset flag.");
|
|
2708
|
+
await disposeInternal();
|
|
2709
|
+
resetInternal();
|
|
2710
|
+
try {
|
|
2711
|
+
configureInternal(config, true);
|
|
2712
|
+
} catch (e) {
|
|
2713
|
+
if (e instanceof ConfigError) {
|
|
2714
|
+
await disposeInternal();
|
|
2715
|
+
resetInternal();
|
|
2716
|
+
}
|
|
2717
|
+
throw e;
|
|
2718
|
+
}
|
|
2719
|
+
});
|
|
1859
2720
|
}
|
|
1860
2721
|
function configureInternal(config, allowAsync) {
|
|
1861
2722
|
currentConfig = config;
|
|
2723
|
+
getInspectionState().configured = true;
|
|
1862
2724
|
let metaConfigured = false;
|
|
2725
|
+
let capturesSourceLocation = false;
|
|
1863
2726
|
const configuredCategories = /* @__PURE__ */ new Set();
|
|
1864
2727
|
for (const cfg of config.loggers) {
|
|
1865
2728
|
if (isLoggerConfigMeta(cfg)) metaConfigured = true;
|
|
@@ -1874,27 +2737,40 @@ function configureInternal(config, allowAsync) {
|
|
|
1874
2737
|
}
|
|
1875
2738
|
logger.parentSinks = cfg.parentSinks ?? "inherit";
|
|
1876
2739
|
if (cfg.lowestLevel !== void 0) logger.lowestLevel = cfg.lowestLevel;
|
|
2740
|
+
if (cfg.captureSourceLocation !== void 0) {
|
|
2741
|
+
if (typeof cfg.captureSourceLocation !== "boolean") throw new ConfigError("Logger captureSourceLocation must be a boolean.");
|
|
2742
|
+
logger.sourceLocationCapture = cfg.captureSourceLocation;
|
|
2743
|
+
if (cfg.captureSourceLocation) capturesSourceLocation = true;
|
|
2744
|
+
}
|
|
1877
2745
|
for (const filterId of cfg.filters ?? []) {
|
|
1878
2746
|
const filter = config.filters?.[filterId];
|
|
1879
2747
|
if (filter === void 0) throw new ConfigError(`Filter not found: ${filterId}.`);
|
|
1880
2748
|
logger.filters.push(toFilter(filter));
|
|
1881
2749
|
}
|
|
2750
|
+
getInspectionState().loggers.set(logger, {
|
|
2751
|
+
sinks: [...logger.sinks],
|
|
2752
|
+
sinkIds: [...cfg.sinks ?? []],
|
|
2753
|
+
filters: [...logger.filters],
|
|
2754
|
+
filterIds: [...cfg.filters ?? []]
|
|
2755
|
+
});
|
|
1882
2756
|
strongRefs.add(logger);
|
|
1883
2757
|
}
|
|
1884
2758
|
LoggerImpl.getLogger().contextLocalStorage = config.contextLocalStorage;
|
|
2759
|
+
getSourceLocationRoot().setGlobalSourceLocationCapture?.(capturesSourceLocation);
|
|
1885
2760
|
for (const sink of Object.values(config.sinks)) {
|
|
1886
|
-
|
|
2761
|
+
installedSinks.add(sink);
|
|
2762
|
+
if (asyncDisposeSymbol in sink) if (allowAsync) asyncSinkDisposables.add(sink);
|
|
1887
2763
|
else throw new ConfigError("Async disposables cannot be used with configureSync().");
|
|
1888
|
-
if (
|
|
2764
|
+
if (disposeSymbol in sink) sinkDisposables.add(sink);
|
|
1889
2765
|
}
|
|
1890
2766
|
for (const filter of Object.values(config.filters ?? {})) {
|
|
1891
2767
|
if (filter == null || typeof filter === "string") continue;
|
|
1892
|
-
if (
|
|
2768
|
+
if (asyncDisposeSymbol in filter) {
|
|
1893
2769
|
if (allowAsync) asyncFilterDisposables.add(filter);
|
|
1894
2770
|
else throw new ConfigError("Async disposables cannot be used with configureSync().");
|
|
1895
2771
|
asyncSinkDisposables.delete(filter);
|
|
1896
2772
|
}
|
|
1897
|
-
if (
|
|
2773
|
+
if (disposeSymbol in filter) {
|
|
1898
2774
|
filterDisposables.add(filter);
|
|
1899
2775
|
sinkDisposables.delete(filter);
|
|
1900
2776
|
}
|
|
@@ -1914,26 +2790,21 @@ function configureInternal(config, allowAsync) {
|
|
|
1914
2790
|
function getConfig() {
|
|
1915
2791
|
return currentConfig;
|
|
1916
2792
|
}
|
|
1917
|
-
/**
|
|
1918
|
-
* Reset the configuration. Mostly for testing purposes.
|
|
1919
|
-
*/
|
|
1920
|
-
async function reset() {
|
|
1921
|
-
await dispose();
|
|
1922
|
-
resetInternal();
|
|
1923
|
-
}
|
|
1924
2793
|
function resetInternal() {
|
|
1925
2794
|
unregisterDisposeHook?.();
|
|
1926
2795
|
unregisterDisposeHook = void 0;
|
|
1927
2796
|
const rootLogger = LoggerImpl.getLogger([]);
|
|
1928
2797
|
rootLogger.resetDescendants();
|
|
2798
|
+
getSourceLocationRoot().setGlobalSourceLocationCapture?.(false);
|
|
1929
2799
|
delete rootLogger.contextLocalStorage;
|
|
1930
2800
|
strongRefs.clear();
|
|
2801
|
+
installedSinks.clear();
|
|
2802
|
+
const inspectionState = getInspectionState();
|
|
2803
|
+
inspectionState.configured = false;
|
|
2804
|
+
inspectionState.loggers = /* @__PURE__ */ new WeakMap();
|
|
1931
2805
|
currentConfig = null;
|
|
1932
2806
|
}
|
|
1933
|
-
|
|
1934
|
-
* Dispose of the disposables.
|
|
1935
|
-
*/
|
|
1936
|
-
async function dispose() {
|
|
2807
|
+
async function disposeInternal() {
|
|
1937
2808
|
const errors = [];
|
|
1938
2809
|
try {
|
|
1939
2810
|
disposeSyncFilters();
|
|
@@ -1957,12 +2828,7 @@ async function dispose() {
|
|
|
1957
2828
|
}
|
|
1958
2829
|
throwDisposeErrors(errors);
|
|
1959
2830
|
}
|
|
1960
|
-
|
|
1961
|
-
* Dispose of the sync disposables. Async disposables will be untouched,
|
|
1962
|
-
* use {@link dispose} if you have async sinks.
|
|
1963
|
-
* @since 0.9.0
|
|
1964
|
-
*/
|
|
1965
|
-
function disposeSync() {
|
|
2831
|
+
function disposeSyncInternal() {
|
|
1966
2832
|
const errors = [];
|
|
1967
2833
|
try {
|
|
1968
2834
|
disposeSyncFilters();
|
|
@@ -1976,6 +2842,18 @@ function disposeSync() {
|
|
|
1976
2842
|
}
|
|
1977
2843
|
throwDisposeErrors(errors);
|
|
1978
2844
|
}
|
|
2845
|
+
async function runGlobalConfigMutation(functionName, callback) {
|
|
2846
|
+
assertCanMutateGlobalConfig(functionName);
|
|
2847
|
+
globalConfigMutationInProgress = true;
|
|
2848
|
+
try {
|
|
2849
|
+
return await callback();
|
|
2850
|
+
} finally {
|
|
2851
|
+
globalConfigMutationInProgress = false;
|
|
2852
|
+
}
|
|
2853
|
+
}
|
|
2854
|
+
function assertCanMutateGlobalConfig(functionName) {
|
|
2855
|
+
if (globalConfigMutationInProgress) throw new ConfigError(`${functionName} cannot be called while LogTape is being reconfigured.`);
|
|
2856
|
+
}
|
|
1979
2857
|
function disposeSyncFilters() {
|
|
1980
2858
|
disposeSyncDisposables(filterDisposables);
|
|
1981
2859
|
}
|
|
@@ -1986,7 +2864,7 @@ function disposeSyncDisposables(disposables) {
|
|
|
1986
2864
|
const errors = [];
|
|
1987
2865
|
try {
|
|
1988
2866
|
for (const disposable of disposables) try {
|
|
1989
|
-
disposable[
|
|
2867
|
+
disposable[disposeSymbol]();
|
|
1990
2868
|
} catch (error) {
|
|
1991
2869
|
errors.push(error);
|
|
1992
2870
|
} finally {
|
|
@@ -2007,7 +2885,7 @@ async function disposeAsyncDisposables(disposables) {
|
|
|
2007
2885
|
const promises = [];
|
|
2008
2886
|
try {
|
|
2009
2887
|
for (const disposable of disposables) try {
|
|
2010
|
-
promises.push(Promise.resolve(disposable[
|
|
2888
|
+
promises.push(Promise.resolve(disposable[asyncDisposeSymbol]()));
|
|
2011
2889
|
} catch (error) {
|
|
2012
2890
|
promises.push(Promise.reject(error));
|
|
2013
2891
|
} finally {
|
|
@@ -2039,8 +2917,7 @@ var ConfigError = class extends Error {
|
|
|
2039
2917
|
this.name = "ConfigError";
|
|
2040
2918
|
}
|
|
2041
2919
|
};
|
|
2042
|
-
|
|
2043
|
-
//#region packages/server/src/observability/logger.ts
|
|
2920
|
+
// packages/server/src/observability/logger.ts
|
|
2044
2921
|
/**
|
|
2045
2922
|
* LogTape configuration entry point.
|
|
2046
2923
|
*
|
|
@@ -2049,7 +2926,7 @@ var ConfigError = class extends Error {
|
|
|
2049
2926
|
* routes to the configured sinks. We expose a small wrapper so the
|
|
2050
2927
|
* boot path can hand LogTape the built-in `"console-json"` shortcut
|
|
2051
2928
|
* (or any custom `Sink` function — pretty rendering lives in
|
|
2052
|
-
* `@baerly/adapter-node` so
|
|
2929
|
+
* `@baerly/adapter-node` so the pretty renderer stays off the kernel) and
|
|
2053
2930
|
* an env-driven level override.
|
|
2054
2931
|
*
|
|
2055
2932
|
* The wrapper is intentionally thin: anything LogTape can do
|
|
@@ -2092,6 +2969,8 @@ var ConfigError = class extends Error {
|
|
|
2092
2969
|
*/
|
|
2093
2970
|
const CATEGORY = {
|
|
2094
2971
|
http: ["baerly", "http"],
|
|
2972
|
+
/** Write-tick maintenance events, routed via `MaintenanceDispatch.warn`. */
|
|
2973
|
+
maintenance: ["baerly", "maintenance"],
|
|
2095
2974
|
storage: ["baerly", "storage"]
|
|
2096
2975
|
};
|
|
2097
2976
|
/**
|
|
@@ -2150,6 +3029,15 @@ const isBaerlyOwnedConfig = (cfg) => Object.prototype.hasOwnProperty.call(cfg.si
|
|
|
2150
3029
|
* strings still work for ad-hoc instrumentation.
|
|
2151
3030
|
*/
|
|
2152
3031
|
const getLogger = (category) => getLogger$1(category);
|
|
3032
|
+
/**
|
|
3033
|
+
* LogTape-backed `MaintenanceDispatch.warn` sink: routes a write-tick
|
|
3034
|
+
* maintenance event (e.g. `fold_deferred`) to {@link CATEGORY.maintenance}
|
|
3035
|
+
* at `warning`. Adapters wire it; the kernel calls it through the
|
|
3036
|
+
* observability context so LogTape stays out of the kernel bundle.
|
|
3037
|
+
*/
|
|
3038
|
+
const logMaintenanceWarning = (event, properties) => {
|
|
3039
|
+
getLogger(CATEGORY.maintenance).warn(event, { ...properties });
|
|
3040
|
+
};
|
|
2153
3041
|
/** Map our friendly `"warn"` onto LogTape's canonical `"warning"`. */
|
|
2154
3042
|
const toLogTapeLevel = (l) => l === "warn" ? "warning" : l;
|
|
2155
3043
|
const resolveLevel = (configLevel) => {
|
|
@@ -2181,16 +3069,44 @@ const jsonConsoleSink = () => (record) => {
|
|
|
2181
3069
|
};
|
|
2182
3070
|
console.log(JSON.stringify(payload));
|
|
2183
3071
|
};
|
|
2184
|
-
|
|
2185
|
-
|
|
3072
|
+
// packages/server/src/observability/derive-outcome.ts
|
|
3073
|
+
/**
|
|
3074
|
+
* Whether `error` is a capacity refusal (`CapacityExceeded` or
|
|
3075
|
+
* `MaintenancePending`): the write was refused before any commit because
|
|
3076
|
+
* the collection is at its host's fold ceiling. Read by the canonical
|
|
3077
|
+
* line's level, which logs these at `warn` even on a 503.
|
|
3078
|
+
*/
|
|
3079
|
+
const isCapacityRefusal = (error) => {
|
|
3080
|
+
const code = error?.code;
|
|
3081
|
+
return code === "CapacityExceeded" || code === "MaintenancePending";
|
|
3082
|
+
};
|
|
2186
3083
|
const deriveOutcome = (method, status, error) => {
|
|
3084
|
+
if (isCapacityRefusal(error)) return "refused";
|
|
2187
3085
|
if (error !== void 0 && status >= 500) return "error";
|
|
2188
3086
|
if (status < 400) return method === "GET" ? "read" : "committed";
|
|
2189
3087
|
if (status === 409) return "conflict";
|
|
2190
3088
|
return "error";
|
|
2191
3089
|
};
|
|
2192
|
-
|
|
2193
|
-
|
|
3090
|
+
// packages/server/src/observability/request-id.ts
|
|
3091
|
+
/**
|
|
3092
|
+
* Characters an inbound request id may use: letters, digits, and the
|
|
3093
|
+
* punctuation found in common id formats (UUID, ULID, W3C `traceparent`,
|
|
3094
|
+
* X-Ray `Root=1-…`, base64). No whitespace, quotes, or control
|
|
3095
|
+
* characters, so a caller cannot forge log structure through it.
|
|
3096
|
+
*/
|
|
3097
|
+
const REQUEST_ID_PATTERN = /^[\w.:/+=@-]+$/;
|
|
3098
|
+
/**
|
|
3099
|
+
* The request id for a unit of work: the caller's `x-request-id` when it
|
|
3100
|
+
* is at most {@link MAX_REQUEST_ID_LENGTH} characters of
|
|
3101
|
+
* {@link REQUEST_ID_PATTERN}, otherwise a fresh UUID. An invalid header
|
|
3102
|
+
* is replaced, not truncated, so a log line never carries part of a
|
|
3103
|
+
* forged value.
|
|
3104
|
+
*/
|
|
3105
|
+
const requestIdFrom = (headers) => {
|
|
3106
|
+
const supplied = headers.get("x-request-id");
|
|
3107
|
+
return supplied !== null && supplied.length <= 128 && REQUEST_ID_PATTERN.test(supplied) ? supplied : crypto.randomUUID();
|
|
3108
|
+
};
|
|
3109
|
+
// packages/server/src/observability/canonical.ts
|
|
2194
3110
|
/**
|
|
2195
3111
|
* Canonical-log-line flusher.
|
|
2196
3112
|
*
|
|
@@ -2209,7 +3125,7 @@ const deriveOutcome = (method, status, error) => {
|
|
|
2209
3125
|
* - `status >= 500` → `error`
|
|
2210
3126
|
* - `status >= 400` → `warn` (client error — a 4xx is the caller's
|
|
2211
3127
|
* fault, not a server fault; an attached structured error, including
|
|
2212
|
-
* a 409
|
|
3128
|
+
* a 409 WriteConflict, does NOT escalate it)
|
|
2213
3129
|
* - `status` 2xx/3xx with an attached `error` → `error` (anomalous)
|
|
2214
3130
|
* - no `status`, `error` present → `error`
|
|
2215
3131
|
* - otherwise → `info`
|
|
@@ -2239,7 +3155,7 @@ const flushCanonicalLine = (ctx, recorder, opts) => {
|
|
|
2239
3155
|
};
|
|
2240
3156
|
/**
|
|
2241
3157
|
* HTTP unit-of-work scope. Opens an {@link ObservabilityContext} from the
|
|
2242
|
-
* inbound `Request` (request id from `x-request-id` header or generated),
|
|
3158
|
+
* inbound `Request` (request id from a valid `x-request-id` header or generated),
|
|
2243
3159
|
* runs `fetch(req)` under {@link runWithContext}, and flushes the canonical
|
|
2244
3160
|
* line in finally with `unit: "http"`.
|
|
2245
3161
|
*
|
|
@@ -2258,7 +3174,8 @@ const flushCanonicalLine = (ctx, recorder, opts) => {
|
|
|
2258
3174
|
* have under the in-Hono middleware.
|
|
2259
3175
|
*/
|
|
2260
3176
|
const withHttpObservability = async (req, fetch) => {
|
|
2261
|
-
const
|
|
3177
|
+
const requestId = requestIdFrom(req.headers);
|
|
3178
|
+
const ctx = createObservabilityContext$1({ request_id: requestId });
|
|
2262
3179
|
const path = new URL(req.url).pathname;
|
|
2263
3180
|
return runWithContext(ctx, async () => {
|
|
2264
3181
|
let response;
|
|
@@ -2335,6 +3252,7 @@ const flushUnauthorizedAndRespond = (obsCtx, req) => {
|
|
|
2335
3252
|
});
|
|
2336
3253
|
};
|
|
2337
3254
|
const pickLevel = (opts) => {
|
|
3255
|
+
if (isCapacityRefusal(opts.error)) return "warn";
|
|
2338
3256
|
if (opts.status !== void 0) {
|
|
2339
3257
|
if (opts.status >= 500) return "error";
|
|
2340
3258
|
if (opts.status >= 400) return "warn";
|
|
@@ -2409,42 +3327,23 @@ const serializeError = (err, includeStack = false) => {
|
|
|
2409
3327
|
message: String(err)
|
|
2410
3328
|
};
|
|
2411
3329
|
};
|
|
2412
|
-
|
|
2413
|
-
//#region packages/server/src/observability/storage.ts
|
|
2414
|
-
/**
|
|
2415
|
-
* `Storage` decorator that emits per-op observability:
|
|
2416
|
-
*
|
|
2417
|
-
* - One histogram observation per call: `db.storage.<op>.duration_ms`.
|
|
2418
|
-
* - One counter increment per call: `db.storage.<op>.calls_total`.
|
|
2419
|
-
* - One counter increment per class A / class B classification:
|
|
2420
|
-
* `db.storage.class_a_ops_total` / `db.storage.class_b_ops_total`.
|
|
2421
|
-
* We follow S3 pricing: PUT / DELETE / LIST count as class A;
|
|
2422
|
-
* GET counts as class B. (S3 charges Class A for PUT/POST/COPY/
|
|
2423
|
-
* LIST and Class B for GET/HEAD; DELETE is free under S3 but
|
|
2424
|
-
* we still count it as class A internally because it triggers
|
|
2425
|
-
* write-side traffic in the kernel's accounting.)
|
|
2426
|
-
* - On error: counter increment `db.storage.<op>.errors_total` and
|
|
2427
|
-
* re-throw the original value verbatim.
|
|
2428
|
-
*
|
|
2429
|
-
* Read paths are NOT decorated by default; consumers pass a
|
|
2430
|
-
* recorder when they want observation. The default no-op recorder
|
|
2431
|
-
* still works — every emission is a single function call.
|
|
2432
|
-
*
|
|
2433
|
-
* The decorator preserves the `Storage` contract exactly: same
|
|
2434
|
-
* input types, same output types, same `null`-on-not-found
|
|
2435
|
-
* convention, same `AsyncIterable` for `list`.
|
|
2436
|
-
*
|
|
2437
|
-
* The debug-level per-call log line is gated on
|
|
2438
|
-
* `getLogger(CATEGORY.storage).isEnabledFor("debug")` so we don't
|
|
2439
|
-
* pay the formatting cost in production where the level is
|
|
2440
|
-
* `info` or higher. (LogTape provides `isEnabledFor` since 2.0.0.)
|
|
2441
|
-
*/
|
|
3330
|
+
// packages/server/src/observability/storage.ts
|
|
2442
3331
|
const CLASS_A_OPS = /* @__PURE__ */ new Set([
|
|
2443
3332
|
"put",
|
|
2444
3333
|
"delete",
|
|
2445
3334
|
"list"
|
|
2446
3335
|
]);
|
|
2447
|
-
const
|
|
3336
|
+
const recordCall = (op) => {
|
|
3337
|
+
const recorder = ctxMetrics();
|
|
3338
|
+
recorder.counter(`db.storage.${op}.calls_total`, 1);
|
|
3339
|
+
recorder.counter(CLASS_A_OPS.has(op) ? "db.storage.class_a_ops_total" : "db.storage.class_b_ops_total", 1);
|
|
3340
|
+
};
|
|
3341
|
+
const recordError = (op) => {
|
|
3342
|
+
ctxMetrics().counter(`db.storage.${op}.errors_total`, 1);
|
|
3343
|
+
};
|
|
3344
|
+
const recordDuration = (op, durationMs) => {
|
|
3345
|
+
ctxMetrics().histogram(`db.storage.${op}.duration_ms`, durationMs);
|
|
3346
|
+
};
|
|
2448
3347
|
/**
|
|
2449
3348
|
* Wrap `inner` with metric emission. The returned object is itself
|
|
2450
3349
|
* a `Storage` impl and passes the `Storage` conformance suite
|
|
@@ -2468,17 +3367,6 @@ const observableStorage = (inner) => {
|
|
|
2468
3367
|
if (bytes !== void 0) props["bytes"] = bytes;
|
|
2469
3368
|
logger.debug("storage", props);
|
|
2470
3369
|
};
|
|
2471
|
-
const recordCall = (op) => {
|
|
2472
|
-
const recorder = ctxMetrics();
|
|
2473
|
-
recorder.counter(`db.storage.${op}.calls_total`, 1);
|
|
2474
|
-
recorder.counter(CLASS_A_OPS.has(op) ? "db.storage.class_a_ops_total" : "db.storage.class_b_ops_total", 1);
|
|
2475
|
-
};
|
|
2476
|
-
const recordError = (op) => {
|
|
2477
|
-
ctxMetrics().counter(`db.storage.${op}.errors_total`, 1);
|
|
2478
|
-
};
|
|
2479
|
-
const recordDuration = (op, durationMs) => {
|
|
2480
|
-
ctxMetrics().histogram(`db.storage.${op}.duration_ms`, durationMs);
|
|
2481
|
-
};
|
|
2482
3370
|
return {
|
|
2483
3371
|
async get(key, opts) {
|
|
2484
3372
|
const op = "get";
|
|
@@ -2555,7 +3443,40 @@ const observableStorage = (inner) => {
|
|
|
2555
3443
|
}
|
|
2556
3444
|
};
|
|
2557
3445
|
};
|
|
2558
|
-
|
|
2559
|
-
|
|
3446
|
+
// packages/server/src/observability/index.ts
|
|
3447
|
+
/**
|
|
3448
|
+
* Observability — per-HTTP-request context, metrics recorder,
|
|
3449
|
+
* canonical-line emission, and the logtape configuration entry point.
|
|
3450
|
+
*
|
|
3451
|
+
* Consumed by the HTTP router (`http/router.ts`) and both adapters
|
|
3452
|
+
* (`@baerly/adapter-cloudflare`, `@baerly/adapter-node`). The
|
|
3453
|
+
* high-level flow:
|
|
3454
|
+
*
|
|
3455
|
+
* 1. The adapter calls {@link configureObservability} once at boot.
|
|
3456
|
+
* 2. Each HTTP request creates an {@link ObservabilityContext} (via
|
|
3457
|
+
* {@link createObservabilityContext} or `withHttpObservability`
|
|
3458
|
+
* for standalone callers that don't have an adapter-managed
|
|
3459
|
+
* scope) and runs the work under {@link runWithContext}.
|
|
3460
|
+
* 3. The adapter calls {@link flushCanonicalLine} at end-of-request;
|
|
3461
|
+
* verifier-rejected requests call `flushUnauthorizedAndRespond`
|
|
3462
|
+
* (adapter wiring on `@baerly/server/_internal/observability`).
|
|
3463
|
+
* 4. Kernel emissions (Writer histograms, compactor / GC gauges,
|
|
3464
|
+
* storage decorator counters) reach the per-request recorder via
|
|
3465
|
+
* the ALS lookup inside emission sites
|
|
3466
|
+
* (`getCurrentContext()?.recorder`). Background runs outside any
|
|
3467
|
+
* HTTP scope emit to the no-op default — by design.
|
|
3468
|
+
*
|
|
3469
|
+
* The `@baerly/server` package re-exports its own `errorEnvelope`
|
|
3470
|
+
* separately; this barrel is the observability seam only.
|
|
3471
|
+
*/
|
|
3472
|
+
/**
|
|
3473
|
+
* Build a per-unit-of-work {@link ObservabilityContext}. Pass it to
|
|
3474
|
+
* {@link runWithContext}; every kernel emission inside reaches its
|
|
3475
|
+
* recorder.
|
|
3476
|
+
*/
|
|
3477
|
+
const createObservabilityContext = createObservabilityContext$1;
|
|
3478
|
+
/** Returns the currently-active context, or `undefined` outside one. */
|
|
3479
|
+
const getCurrentContext = getCurrentContext$1;
|
|
3480
|
+
export { flushUnauthorizedAndRespond as a, requestIdFrom as c, configureObservability as d, getLogger as f, flushCanonicalLine as i, deriveOutcome as l, errorEnvelope as m, getCurrentContext as n, serializeError as o, logMaintenanceWarning as p, observableStorage as r, withHttpObservability as s, createObservabilityContext as t, CATEGORY as u };
|
|
2560
3481
|
|
|
2561
|
-
//# sourceMappingURL=observability-
|
|
3482
|
+
//# sourceMappingURL=observability-C-ISCCLE.js.map
|