@oscharko-dev/keiko 0.3.13 → 0.3.15
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/dist/ui/csp-hashes.json +6 -6
- package/dist/ui/static/404.html +1 -1
- package/dist/ui/static/__next.__PAGE__.txt +1 -1
- package/dist/ui/static/__next._full.txt +1 -1
- package/dist/ui/static/__next._head.txt +1 -1
- package/dist/ui/static/__next._index.txt +1 -1
- package/dist/ui/static/__next._tree.txt +1 -1
- package/dist/ui/static/_not-found/__next._full.txt +1 -1
- package/dist/ui/static/_not-found/__next._head.txt +1 -1
- package/dist/ui/static/_not-found/__next._index.txt +1 -1
- package/dist/ui/static/_not-found/__next._not-found.__PAGE__.txt +1 -1
- package/dist/ui/static/_not-found/__next._not-found.txt +1 -1
- package/dist/ui/static/_not-found/__next._tree.txt +1 -1
- package/dist/ui/static/_not-found.html +1 -1
- package/dist/ui/static/_not-found.txt +1 -1
- package/dist/ui/static/atlassian-connectors/__next._full.txt +1 -1
- package/dist/ui/static/atlassian-connectors/__next._head.txt +1 -1
- package/dist/ui/static/atlassian-connectors/__next._index.txt +1 -1
- package/dist/ui/static/atlassian-connectors/__next._tree.txt +1 -1
- package/dist/ui/static/atlassian-connectors/__next.atlassian-connectors.__PAGE__.txt +1 -1
- package/dist/ui/static/atlassian-connectors/__next.atlassian-connectors.txt +1 -1
- package/dist/ui/static/atlassian-connectors.html +1 -1
- package/dist/ui/static/atlassian-connectors.txt +1 -1
- package/dist/ui/static/index.html +1 -1
- package/dist/ui/static/index.txt +1 -1
- package/dist/ui/static/launch/__next._full.txt +1 -1
- package/dist/ui/static/launch/__next._head.txt +1 -1
- package/dist/ui/static/launch/__next._index.txt +1 -1
- package/dist/ui/static/launch/__next._tree.txt +1 -1
- package/dist/ui/static/launch/__next.launch.__PAGE__.txt +1 -1
- package/dist/ui/static/launch/__next.launch.txt +1 -1
- package/dist/ui/static/launch.html +1 -1
- package/dist/ui/static/launch.txt +1 -1
- package/dist/ui/static/local-knowledge/__next._full.txt +1 -1
- package/dist/ui/static/local-knowledge/__next._head.txt +1 -1
- package/dist/ui/static/local-knowledge/__next._index.txt +1 -1
- package/dist/ui/static/local-knowledge/__next._tree.txt +1 -1
- package/dist/ui/static/local-knowledge/__next.local-knowledge.__PAGE__.txt +1 -1
- package/dist/ui/static/local-knowledge/__next.local-knowledge.txt +1 -1
- package/dist/ui/static/local-knowledge/capsule/__next._full.txt +1 -1
- package/dist/ui/static/local-knowledge/capsule/__next._head.txt +1 -1
- package/dist/ui/static/local-knowledge/capsule/__next._index.txt +1 -1
- package/dist/ui/static/local-knowledge/capsule/__next._tree.txt +1 -1
- package/dist/ui/static/local-knowledge/capsule/__next.local-knowledge.capsule.__PAGE__.txt +1 -1
- package/dist/ui/static/local-knowledge/capsule/__next.local-knowledge.capsule.txt +1 -1
- package/dist/ui/static/local-knowledge/capsule/__next.local-knowledge.txt +1 -1
- package/dist/ui/static/local-knowledge/capsule.html +1 -1
- package/dist/ui/static/local-knowledge/capsule.txt +1 -1
- package/dist/ui/static/local-knowledge.html +1 -1
- package/dist/ui/static/local-knowledge.txt +1 -1
- package/node_modules/@oscharko-dev/keiko-cli/dist/ui.d.ts.map +1 -1
- package/node_modules/@oscharko-dev/keiko-cli/dist/ui.js +25 -6
- package/node_modules/@oscharko-dev/keiko-cli/package.json +13 -13
- package/node_modules/@oscharko-dev/keiko-connectors/package.json +3 -3
- package/node_modules/@oscharko-dev/keiko-contracts/dist/index.d.ts +2 -2
- package/node_modules/@oscharko-dev/keiko-contracts/dist/index.js +2 -2
- package/node_modules/@oscharko-dev/keiko-contracts/package.json +1 -1
- package/node_modules/@oscharko-dev/keiko-evaluations/package.json +9 -9
- package/node_modules/@oscharko-dev/keiko-evidence/dist/version.d.ts +1 -1
- package/node_modules/@oscharko-dev/keiko-evidence/dist/version.js +1 -1
- package/node_modules/@oscharko-dev/keiko-evidence/package.json +4 -4
- package/node_modules/@oscharko-dev/keiko-git/package.json +1 -1
- package/node_modules/@oscharko-dev/keiko-harness/dist/version.d.ts +1 -1
- package/node_modules/@oscharko-dev/keiko-harness/dist/version.js +1 -1
- package/node_modules/@oscharko-dev/keiko-harness/package.json +6 -6
- package/node_modules/@oscharko-dev/keiko-local-knowledge/dist/connector-pod.d.ts +2 -0
- package/node_modules/@oscharko-dev/keiko-local-knowledge/dist/connector-pod.d.ts.map +1 -1
- package/node_modules/@oscharko-dev/keiko-local-knowledge/dist/connector-pod.js +1 -0
- package/node_modules/@oscharko-dev/keiko-local-knowledge/dist/index.d.ts +1 -0
- package/node_modules/@oscharko-dev/keiko-local-knowledge/dist/index.d.ts.map +1 -1
- package/node_modules/@oscharko-dev/keiko-local-knowledge/dist/index.js +3 -0
- package/node_modules/@oscharko-dev/keiko-local-knowledge/dist/indexing/embedding-batcher.d.ts +1 -0
- package/node_modules/@oscharko-dev/keiko-local-knowledge/dist/indexing/embedding-batcher.d.ts.map +1 -1
- package/node_modules/@oscharko-dev/keiko-local-knowledge/dist/indexing/embedding-batcher.js +341 -62
- package/node_modules/@oscharko-dev/keiko-local-knowledge/dist/indexing/orchestrator.d.ts.map +1 -1
- package/node_modules/@oscharko-dev/keiko-local-knowledge/dist/indexing/orchestrator.js +586 -132
- package/node_modules/@oscharko-dev/keiko-local-knowledge/dist/indexing/types.d.ts +9 -0
- package/node_modules/@oscharko-dev/keiko-local-knowledge/dist/indexing/types.d.ts.map +1 -1
- package/node_modules/@oscharko-dev/keiko-local-knowledge/dist/knowledge-log.d.ts +20 -0
- package/node_modules/@oscharko-dev/keiko-local-knowledge/dist/knowledge-log.d.ts.map +1 -0
- package/node_modules/@oscharko-dev/keiko-local-knowledge/dist/knowledge-log.js +154 -0
- package/node_modules/@oscharko-dev/keiko-local-knowledge/dist/manual-pod-refresh.d.ts +2 -0
- package/node_modules/@oscharko-dev/keiko-local-knowledge/dist/manual-pod-refresh.d.ts.map +1 -1
- package/node_modules/@oscharko-dev/keiko-local-knowledge/dist/manual-pod-refresh.js +1 -0
- package/node_modules/@oscharko-dev/keiko-local-knowledge/dist/manual-pod.d.ts +2 -0
- package/node_modules/@oscharko-dev/keiko-local-knowledge/dist/manual-pod.d.ts.map +1 -1
- package/node_modules/@oscharko-dev/keiko-local-knowledge/dist/manual-pod.js +1 -0
- package/node_modules/@oscharko-dev/keiko-local-knowledge/dist/repository-pod.d.ts +2 -0
- package/node_modules/@oscharko-dev/keiko-local-knowledge/dist/repository-pod.d.ts.map +1 -1
- package/node_modules/@oscharko-dev/keiko-local-knowledge/dist/repository-pod.js +1 -0
- package/node_modules/@oscharko-dev/keiko-local-knowledge/dist/store.d.ts +2 -0
- package/node_modules/@oscharko-dev/keiko-local-knowledge/dist/store.d.ts.map +1 -1
- package/node_modules/@oscharko-dev/keiko-local-knowledge/dist/store.js +43 -1
- package/node_modules/@oscharko-dev/keiko-local-knowledge/dist/version.d.ts +1 -1
- package/node_modules/@oscharko-dev/keiko-local-knowledge/dist/version.js +1 -1
- package/node_modules/@oscharko-dev/keiko-local-knowledge/package.json +5 -5
- package/node_modules/@oscharko-dev/keiko-memory-capture/dist/version.d.ts +1 -1
- package/node_modules/@oscharko-dev/keiko-memory-capture/dist/version.js +1 -1
- package/node_modules/@oscharko-dev/keiko-memory-capture/package.json +3 -3
- package/node_modules/@oscharko-dev/keiko-memory-consolidation/dist/version.d.ts +1 -1
- package/node_modules/@oscharko-dev/keiko-memory-consolidation/dist/version.js +1 -1
- package/node_modules/@oscharko-dev/keiko-memory-consolidation/package.json +3 -3
- package/node_modules/@oscharko-dev/keiko-memory-governance/dist/version.d.ts +1 -1
- package/node_modules/@oscharko-dev/keiko-memory-governance/dist/version.js +1 -1
- package/node_modules/@oscharko-dev/keiko-memory-governance/package.json +3 -3
- package/node_modules/@oscharko-dev/keiko-memory-retrieval/dist/version.d.ts +1 -1
- package/node_modules/@oscharko-dev/keiko-memory-retrieval/dist/version.js +1 -1
- package/node_modules/@oscharko-dev/keiko-memory-retrieval/package.json +3 -3
- package/node_modules/@oscharko-dev/keiko-memory-vault/dist/version.d.ts +1 -1
- package/node_modules/@oscharko-dev/keiko-memory-vault/dist/version.js +1 -1
- package/node_modules/@oscharko-dev/keiko-memory-vault/package.json +3 -3
- package/node_modules/@oscharko-dev/keiko-model-gateway/dist/gateway.d.ts +15 -2
- package/node_modules/@oscharko-dev/keiko-model-gateway/dist/gateway.d.ts.map +1 -1
- package/node_modules/@oscharko-dev/keiko-model-gateway/dist/gateway.js +147 -15
- package/node_modules/@oscharko-dev/keiko-model-gateway/dist/http.d.ts +3 -0
- package/node_modules/@oscharko-dev/keiko-model-gateway/dist/http.d.ts.map +1 -1
- package/node_modules/@oscharko-dev/keiko-model-gateway/dist/http.js +188 -23
- package/node_modules/@oscharko-dev/keiko-model-gateway/dist/observability.d.ts +27 -0
- package/node_modules/@oscharko-dev/keiko-model-gateway/dist/observability.d.ts.map +1 -0
- package/node_modules/@oscharko-dev/keiko-model-gateway/dist/observability.js +180 -0
- package/node_modules/@oscharko-dev/keiko-model-gateway/dist/openai-embedding-adapter.d.ts +5 -0
- package/node_modules/@oscharko-dev/keiko-model-gateway/dist/openai-embedding-adapter.d.ts.map +1 -1
- package/node_modules/@oscharko-dev/keiko-model-gateway/dist/openai-embedding-adapter.js +339 -55
- package/node_modules/@oscharko-dev/keiko-model-gateway/dist/resilience.d.ts +18 -5
- package/node_modules/@oscharko-dev/keiko-model-gateway/dist/resilience.d.ts.map +1 -1
- package/node_modules/@oscharko-dev/keiko-model-gateway/dist/resilience.js +141 -26
- package/node_modules/@oscharko-dev/keiko-model-gateway/dist/version.d.ts +1 -1
- package/node_modules/@oscharko-dev/keiko-model-gateway/dist/version.js +1 -1
- package/node_modules/@oscharko-dev/keiko-model-gateway/package.json +3 -3
- package/node_modules/@oscharko-dev/keiko-quality-intelligence/package.json +3 -3
- package/node_modules/@oscharko-dev/keiko-sandbox/package.json +2 -2
- package/node_modules/@oscharko-dev/keiko-sdk/package.json +9 -9
- package/node_modules/@oscharko-dev/keiko-security/dist/version.d.ts +1 -1
- package/node_modules/@oscharko-dev/keiko-security/dist/version.js +1 -1
- package/node_modules/@oscharko-dev/keiko-security/package.json +2 -2
- package/node_modules/@oscharko-dev/keiko-server/dist/atlassian/syncService.d.ts.map +1 -1
- package/node_modules/@oscharko-dev/keiko-server/dist/atlassian/syncService.js +4 -0
- package/node_modules/@oscharko-dev/keiko-server/dist/bounded-request-body.d.ts +1 -1
- package/node_modules/@oscharko-dev/keiko-server/dist/bounded-request-body.d.ts.map +1 -1
- package/node_modules/@oscharko-dev/keiko-server/dist/bounded-request-body.js +51 -3
- package/node_modules/@oscharko-dev/keiko-server/dist/diagnostics-log.d.ts.map +1 -1
- package/node_modules/@oscharko-dev/keiko-server/dist/diagnostics-log.js +77 -3
- package/node_modules/@oscharko-dev/keiko-server/dist/gateway-instance-cache.d.ts.map +1 -1
- package/node_modules/@oscharko-dev/keiko-server/dist/gateway-instance-cache.js +71 -11
- package/node_modules/@oscharko-dev/keiko-server/dist/gateway-setup.d.ts.map +1 -1
- package/node_modules/@oscharko-dev/keiko-server/dist/gateway-setup.js +9 -1
- package/node_modules/@oscharko-dev/keiko-server/dist/grounded-qa.js +1 -1
- package/node_modules/@oscharko-dev/keiko-server/dist/grounded-rerank-facade.d.ts.map +1 -1
- package/node_modules/@oscharko-dev/keiko-server/dist/grounded-rerank-facade.js +37 -0
- package/node_modules/@oscharko-dev/keiko-server/dist/index.d.ts +1 -0
- package/node_modules/@oscharko-dev/keiko-server/dist/index.d.ts.map +1 -1
- package/node_modules/@oscharko-dev/keiko-server/dist/index.js +7 -0
- package/node_modules/@oscharko-dev/keiko-server/dist/local-knowledge-handlers.d.ts.map +1 -1
- package/node_modules/@oscharko-dev/keiko-server/dist/local-knowledge-handlers.js +158 -36
- package/node_modules/@oscharko-dev/keiko-server/dist/local-knowledge-remediation-store.d.ts.map +1 -1
- package/node_modules/@oscharko-dev/keiko-server/dist/local-knowledge-remediation-store.js +9 -1
- package/node_modules/@oscharko-dev/keiko-server/dist/local-knowledge-remediation.d.ts.map +1 -1
- package/node_modules/@oscharko-dev/keiko-server/dist/local-knowledge-remediation.js +10 -5
- package/node_modules/@oscharko-dev/keiko-server/dist/local-knowledge-store-open.d.ts.map +1 -1
- package/node_modules/@oscharko-dev/keiko-server/dist/local-knowledge-store-open.js +8 -2
- package/node_modules/@oscharko-dev/keiko-server/dist/manual/manual-pod-service.d.ts.map +1 -1
- package/node_modules/@oscharko-dev/keiko-server/dist/manual/manual-pod-service.js +3 -0
- package/node_modules/@oscharko-dev/keiko-server/dist/memory-embedding.d.ts.map +1 -1
- package/node_modules/@oscharko-dev/keiko-server/dist/memory-embedding.js +135 -36
- package/node_modules/@oscharko-dev/keiko-server/dist/observability/index.d.ts +3 -0
- package/node_modules/@oscharko-dev/keiko-server/dist/observability/index.d.ts.map +1 -0
- package/node_modules/@oscharko-dev/keiko-server/dist/observability/index.js +9 -0
- package/node_modules/@oscharko-dev/keiko-server/dist/observability/log-level.d.ts +13 -0
- package/node_modules/@oscharko-dev/keiko-server/dist/observability/log-level.d.ts.map +1 -0
- package/node_modules/@oscharko-dev/keiko-server/dist/observability/log-level.js +57 -0
- package/node_modules/@oscharko-dev/keiko-server/dist/observability/log-redaction.d.ts +20 -0
- package/node_modules/@oscharko-dev/keiko-server/dist/observability/log-redaction.d.ts.map +1 -0
- package/node_modules/@oscharko-dev/keiko-server/dist/observability/log-redaction.js +499 -0
- package/node_modules/@oscharko-dev/keiko-server/dist/observability/route-template.d.ts +4 -0
- package/node_modules/@oscharko-dev/keiko-server/dist/observability/route-template.d.ts.map +1 -0
- package/node_modules/@oscharko-dev/keiko-server/dist/observability/route-template.js +340 -0
- package/node_modules/@oscharko-dev/keiko-server/dist/observability/server-log.d.ts +49 -0
- package/node_modules/@oscharko-dev/keiko-server/dist/observability/server-log.d.ts.map +1 -0
- package/node_modules/@oscharko-dev/keiko-server/dist/observability/server-log.js +449 -0
- package/node_modules/@oscharko-dev/keiko-server/dist/observability/server-logger.d.ts +36 -0
- package/node_modules/@oscharko-dev/keiko-server/dist/observability/server-logger.d.ts.map +1 -0
- package/node_modules/@oscharko-dev/keiko-server/dist/observability/server-logger.js +190 -0
- package/node_modules/@oscharko-dev/keiko-server/dist/process-log-sink.d.ts +11 -0
- package/node_modules/@oscharko-dev/keiko-server/dist/process-log-sink.d.ts.map +1 -0
- package/node_modules/@oscharko-dev/keiko-server/dist/process-log-sink.js +48 -0
- package/node_modules/@oscharko-dev/keiko-server/dist/server.d.ts +2 -0
- package/node_modules/@oscharko-dev/keiko-server/dist/server.d.ts.map +1 -1
- package/node_modules/@oscharko-dev/keiko-server/dist/server.js +22 -4
- package/node_modules/@oscharko-dev/keiko-server/dist/store-handlers.d.ts.map +1 -1
- package/node_modules/@oscharko-dev/keiko-server/dist/store-handlers.js +7 -2
- package/node_modules/@oscharko-dev/keiko-server/package.json +21 -21
- package/node_modules/@oscharko-dev/keiko-tools/dist/version.d.ts +1 -1
- package/node_modules/@oscharko-dev/keiko-tools/dist/version.js +1 -1
- package/node_modules/@oscharko-dev/keiko-tools/package.json +5 -5
- package/node_modules/@oscharko-dev/keiko-verification/package.json +5 -5
- package/node_modules/@oscharko-dev/keiko-workflows/package.json +10 -10
- package/node_modules/@oscharko-dev/keiko-workspace/dist/version.d.ts +1 -1
- package/node_modules/@oscharko-dev/keiko-workspace/dist/version.js +1 -1
- package/node_modules/@oscharko-dev/keiko-workspace/package.json +3 -3
- package/package.json +25 -25
- package/release-impact.catalog.json +117 -7
- package/vendor/{oscharko-dev-keiko-cli-0.3.13.tgz → oscharko-dev-keiko-cli-0.3.15.tgz} +0 -0
- package/vendor/{oscharko-dev-keiko-connectors-0.3.13.tgz → oscharko-dev-keiko-connectors-0.3.15.tgz} +0 -0
- package/vendor/{oscharko-dev-keiko-contracts-0.3.13.tgz → oscharko-dev-keiko-contracts-0.3.15.tgz} +0 -0
- package/vendor/{oscharko-dev-keiko-evaluations-0.3.13.tgz → oscharko-dev-keiko-evaluations-0.3.15.tgz} +0 -0
- package/vendor/{oscharko-dev-keiko-evidence-0.3.13.tgz → oscharko-dev-keiko-evidence-0.3.15.tgz} +0 -0
- package/vendor/{oscharko-dev-keiko-git-0.3.13.tgz → oscharko-dev-keiko-git-0.3.15.tgz} +0 -0
- package/vendor/{oscharko-dev-keiko-harness-0.3.13.tgz → oscharko-dev-keiko-harness-0.3.15.tgz} +0 -0
- package/vendor/oscharko-dev-keiko-local-knowledge-0.3.15.tgz +0 -0
- package/vendor/{oscharko-dev-keiko-memory-capture-0.3.13.tgz → oscharko-dev-keiko-memory-capture-0.3.15.tgz} +0 -0
- package/vendor/{oscharko-dev-keiko-memory-consolidation-0.3.13.tgz → oscharko-dev-keiko-memory-consolidation-0.3.15.tgz} +0 -0
- package/vendor/oscharko-dev-keiko-memory-governance-0.3.15.tgz +0 -0
- package/vendor/{oscharko-dev-keiko-memory-retrieval-0.3.13.tgz → oscharko-dev-keiko-memory-retrieval-0.3.15.tgz} +0 -0
- package/vendor/{oscharko-dev-keiko-memory-vault-0.3.13.tgz → oscharko-dev-keiko-memory-vault-0.3.15.tgz} +0 -0
- package/vendor/oscharko-dev-keiko-model-gateway-0.3.15.tgz +0 -0
- package/vendor/{oscharko-dev-keiko-quality-intelligence-0.3.13.tgz → oscharko-dev-keiko-quality-intelligence-0.3.15.tgz} +0 -0
- package/vendor/{oscharko-dev-keiko-sandbox-0.3.13.tgz → oscharko-dev-keiko-sandbox-0.3.15.tgz} +0 -0
- package/vendor/oscharko-dev-keiko-sdk-0.3.15.tgz +0 -0
- package/vendor/{oscharko-dev-keiko-security-0.3.13.tgz → oscharko-dev-keiko-security-0.3.15.tgz} +0 -0
- package/vendor/oscharko-dev-keiko-server-0.3.15.tgz +0 -0
- package/vendor/{oscharko-dev-keiko-tools-0.3.13.tgz → oscharko-dev-keiko-tools-0.3.15.tgz} +0 -0
- package/vendor/{oscharko-dev-keiko-verification-0.3.13.tgz → oscharko-dev-keiko-verification-0.3.15.tgz} +0 -0
- package/vendor/{oscharko-dev-keiko-workflows-0.3.13.tgz → oscharko-dev-keiko-workflows-0.3.15.tgz} +0 -0
- package/vendor/{oscharko-dev-keiko-workspace-0.3.13.tgz → oscharko-dev-keiko-workspace-0.3.15.tgz} +0 -0
- package/vendor/oscharko-dev-keiko-local-knowledge-0.3.13.tgz +0 -0
- package/vendor/oscharko-dev-keiko-memory-governance-0.3.13.tgz +0 -0
- package/vendor/oscharko-dev-keiko-model-gateway-0.3.13.tgz +0 -0
- package/vendor/oscharko-dev-keiko-sdk-0.3.13.tgz +0 -0
- package/vendor/oscharko-dev-keiko-server-0.3.13.tgz +0 -0
- /package/dist/ui/static/_next/static/{iwhpaHGb663ka5R3lhZBj → 4j3JDaPBERRu_ZIgeR1VQ}/_buildManifest.js +0 -0
- /package/dist/ui/static/_next/static/{iwhpaHGb663ka5R3lhZBj → 4j3JDaPBERRu_ZIgeR1VQ}/_clientMiddlewareManifest.js +0 -0
- /package/dist/ui/static/_next/static/{iwhpaHGb663ka5R3lhZBj → 4j3JDaPBERRu_ZIgeR1VQ}/_ssgManifest.js +0 -0
|
@@ -0,0 +1,449 @@
|
|
|
1
|
+
// Server activity log — one JSON line per operation into `<stateDir>/logs/server.log`, with
|
|
2
|
+
// day-based rotation and a rolling 7-day retention. Written unconditionally, no env-var opt-in:
|
|
3
|
+
// operators facing a stuck run must not have to know a magic switch to see what the process is
|
|
4
|
+
// doing. Redaction stays strict — endpoints, sizes, HTTP statuses, error kinds and correlation
|
|
5
|
+
// ids only; request bodies, response bodies, tokens, api-keys and user text never appear, and
|
|
6
|
+
// that is enforced structurally by `log-redaction.ts` rather than by caller discipline.
|
|
7
|
+
//
|
|
8
|
+
// WHY THE WRITE IS SYNCHRONOUS (and stays that way)
|
|
9
|
+
//
|
|
10
|
+
// The failure this log exists to diagnose is a process that stops making progress: a six-minute
|
|
11
|
+
// wall inside an embedding batch, a wedged proxy CONNECT, a migration holding a transaction. A
|
|
12
|
+
// write-behind queue is exactly wrong for that shape — the lines an operator needs are the last
|
|
13
|
+
// ones before the wedge, and those are the ones a queue still holds when the event loop stops
|
|
14
|
+
// turning or the process is killed. Synchronous append is the only mode where "the line is in the
|
|
15
|
+
// file" and "the operation happened" cannot come apart.
|
|
16
|
+
//
|
|
17
|
+
// The cost is bounded and pinned by COUNTING, not by timing. The sink holds ONE append-mode
|
|
18
|
+
// descriptor open for the life of the file, so a line costs a single `write(2)` rather than the
|
|
19
|
+
// open/write/close triple `appendFileSync` pays per call. `server-log.test.ts` asserts exactly
|
|
20
|
+
// that over a burst — one `openSync`, one `writeSync` per line, and a file whose size is N times
|
|
21
|
+
// one line — so a regression to per-write open/close, or to a quadratic format path, fails the
|
|
22
|
+
// suite deterministically instead of showing up as latency in production. A wall-clock budget
|
|
23
|
+
// would measure the runner's disk instead, and go red on a diff that never touched this file.
|
|
24
|
+
//
|
|
25
|
+
// Levels are the volume control instead: an event below the configured threshold returns before
|
|
26
|
+
// any string or JSON work happens at all (`KEIKO_LOG_LEVEL`, default `info`).
|
|
27
|
+
import { closeSync, existsSync, linkSync, mkdirSync, openSync, readdirSync, renameSync, unlinkSync, writeSync, } from "node:fs";
|
|
28
|
+
import { join, resolve as resolvePath } from "node:path";
|
|
29
|
+
import { DEFAULT_SERVER_LOG_LEVEL, resolveServerLogThreshold, serverLogLevelEnabled, } from "./log-level.js";
|
|
30
|
+
import { redactLogFields, redactLogLabel } from "./log-redaction.js";
|
|
31
|
+
export { DEFAULT_SERVER_LOG_LEVEL, SERVER_LOG_LEVELS, SERVER_LOG_LEVEL_ENV, isServerLogLevel, isServerLogThreshold, parseServerLogThreshold, resolveServerLogThreshold, serverLogLevelEnabled, serverLogLevelRank, } from "./log-level.js";
|
|
32
|
+
export { MAX_LOG_ARRAY_LENGTH, MAX_LOG_FIELD_COUNT, MAX_LOG_FIELD_DEPTH, MAX_LOG_STRING_LENGTH, REDACTED_KEY, REDACTED_LENGTH, REDACTED_PATH, REDACTED_PERSONAL, REDACTED_SECRET, REDACTED_SHAPE, DROPPED_DEPTH, isDeniedLogFieldName, normalizeLogFieldName, redactLogFields, redactLogLabel, redactLogString, } from "./log-redaction.js";
|
|
33
|
+
export { redactRoutePath } from "./route-template.js";
|
|
34
|
+
export const DEFAULT_LOG_RETENTION_DAYS = 7;
|
|
35
|
+
// A hard ceiling on one serialised line. Every field guard runs first, so reaching this means a
|
|
36
|
+
// caller passed an unexpected shape; the line is replaced rather than written, so one pathological
|
|
37
|
+
// event cannot fill a disk or blow a log shipper's line limit.
|
|
38
|
+
export const MAX_LOG_LINE_BYTES = 8192;
|
|
39
|
+
const NULL_SINK = {
|
|
40
|
+
write(_event) {
|
|
41
|
+
// Explicit noop for tests and for environments without a state directory.
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
export function nullServerLogSink() {
|
|
45
|
+
return NULL_SINK;
|
|
46
|
+
}
|
|
47
|
+
const ERROR_KIND_PATTERN = /^[A-Za-z][A-Za-z0-9_.-]{0,63}$/;
|
|
48
|
+
function readStringProperty(source, key) {
|
|
49
|
+
const value = source[key];
|
|
50
|
+
return typeof value === "string" && ERROR_KIND_PATTERN.test(value) ? value : undefined;
|
|
51
|
+
}
|
|
52
|
+
// Turns an unknown thrown value into a content-free classification: a coded error's `code`, else
|
|
53
|
+
// the error's `name`, else `unknown`. The MESSAGE is never read — that is the whole point, and it
|
|
54
|
+
// is why instrumentation sites should call this instead of `String(error)`. It lives here rather
|
|
55
|
+
// than beside the logger because the file sink below classifies its own failures too, and this
|
|
56
|
+
// module is the one both sides already depend on.
|
|
57
|
+
export function errorKindOf(error) {
|
|
58
|
+
if (typeof error !== "object" || error === null)
|
|
59
|
+
return "unknown";
|
|
60
|
+
return readStringProperty(error, "code") ?? readStringProperty(error, "name") ?? "unknown";
|
|
61
|
+
}
|
|
62
|
+
// LAST-RESORT FAILURE NOTICE
|
|
63
|
+
//
|
|
64
|
+
// Every layer below the caller swallows its own failures on purpose: a log line is evidence about
|
|
65
|
+
// an operation and must never become a new failure mode for it. Swallowed SILENTLY, though, a
|
|
66
|
+
// permanently broken log looks exactly like a quiet system — which is the precise silence this
|
|
67
|
+
// module exists to end, and the reason four releases shipped against a stuck indexing run.
|
|
68
|
+
//
|
|
69
|
+
// So a failure is reported once, on an INDEPENDENT channel: stderr, never the sink that just
|
|
70
|
+
// failed. A full disk cannot be diagnosed by writing to the disk. The notice carries the same
|
|
71
|
+
// body-free shape as a log line — a classification, the op, the correlation id — and is throttled,
|
|
72
|
+
// because the failures this catches sit inside per-item loops: a broken descriptor must not turn
|
|
73
|
+
// one flood into another. Suppressed notices are counted and reported on the next one, so the
|
|
74
|
+
// throttle never hides the SCALE of the failure, only its repetition.
|
|
75
|
+
const LOG_FAILURE_NOTICE_OP = "server-log.write-failed";
|
|
76
|
+
export const LOG_FAILURE_NOTICE_WINDOW_MS = 60_000;
|
|
77
|
+
const failureNotice = { lastAt: null, suppressed: 0 };
|
|
78
|
+
// Tests reset this so one suite's notice cannot silence the next suite's assertion; the server
|
|
79
|
+
// resets it on shutdown for the same reason.
|
|
80
|
+
export function resetServerLogFailureNotices() {
|
|
81
|
+
failureNotice.lastAt = null;
|
|
82
|
+
failureNotice.suppressed = 0;
|
|
83
|
+
}
|
|
84
|
+
function noticeIsThrottled(now) {
|
|
85
|
+
const last = failureNotice.lastAt;
|
|
86
|
+
if (last === null)
|
|
87
|
+
return false;
|
|
88
|
+
const elapsed = now - last;
|
|
89
|
+
// A backwards system-clock adjustment must not silence the notice for a minute: an elapsed time
|
|
90
|
+
// we cannot trust fails toward visibility.
|
|
91
|
+
return elapsed >= 0 && elapsed < LOG_FAILURE_NOTICE_WINDOW_MS;
|
|
92
|
+
}
|
|
93
|
+
export function reportServerLogFailure(error, context = {}) {
|
|
94
|
+
const now = Date.now();
|
|
95
|
+
if (noticeIsThrottled(now)) {
|
|
96
|
+
failureNotice.suppressed += 1;
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
const suppressed = failureNotice.suppressed;
|
|
100
|
+
failureNotice.lastAt = now;
|
|
101
|
+
failureNotice.suppressed = 0;
|
|
102
|
+
emitFailureNotice(error, context, suppressed, now);
|
|
103
|
+
}
|
|
104
|
+
function emitFailureNotice(error, context, suppressed, now) {
|
|
105
|
+
const notice = {
|
|
106
|
+
ts: new Date(now).toISOString(),
|
|
107
|
+
level: "error",
|
|
108
|
+
category: "diagnostic",
|
|
109
|
+
op: LOG_FAILURE_NOTICE_OP,
|
|
110
|
+
errorKind: errorKindOf(error),
|
|
111
|
+
};
|
|
112
|
+
if (context.op !== undefined)
|
|
113
|
+
notice.failedOp = redactLogLabel(context.op);
|
|
114
|
+
if (context.correlationId !== undefined) {
|
|
115
|
+
notice.correlationId = redactLogLabel(context.correlationId);
|
|
116
|
+
}
|
|
117
|
+
if (suppressed > 0)
|
|
118
|
+
notice.suppressedNotices = suppressed;
|
|
119
|
+
try {
|
|
120
|
+
process.stderr.write(`${JSON.stringify(notice)}\n`);
|
|
121
|
+
}
|
|
122
|
+
catch {
|
|
123
|
+
// There is no third channel. A diagnostic that cannot be delivered must not fail the
|
|
124
|
+
// operation it was describing.
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
function eventLevel(event) {
|
|
128
|
+
return event.level ?? DEFAULT_SERVER_LOG_LEVEL;
|
|
129
|
+
}
|
|
130
|
+
function finiteOrUndefined(value) {
|
|
131
|
+
return typeof value === "number" && Number.isFinite(value) ? value : undefined;
|
|
132
|
+
}
|
|
133
|
+
function applyEnvelopeFields(record, event) {
|
|
134
|
+
if (event.correlationId !== undefined)
|
|
135
|
+
record.correlationId = redactLogLabel(event.correlationId);
|
|
136
|
+
const durationMs = finiteOrUndefined(event.durationMs);
|
|
137
|
+
if (durationMs !== undefined)
|
|
138
|
+
record.durationMs = durationMs;
|
|
139
|
+
const status = finiteOrUndefined(event.status);
|
|
140
|
+
if (status !== undefined)
|
|
141
|
+
record.status = status;
|
|
142
|
+
if (event.errorKind !== undefined)
|
|
143
|
+
record.errorKind = redactLogLabel(event.errorKind);
|
|
144
|
+
}
|
|
145
|
+
// `ts`, `level`, `category` and `op` are written first and are reserved inside `redactLogFields`,
|
|
146
|
+
// so `extra` cannot spoof the identity of a line. The remaining envelope fields are applied AFTER
|
|
147
|
+
// `extra` so an explicit `durationMs`/`status`/`errorKind` on the event wins, while an
|
|
148
|
+
// instrumentation site that carries the same name in its field list still gets it logged.
|
|
149
|
+
export function formatServerLogLine(event, now = new Date()) {
|
|
150
|
+
const record = {
|
|
151
|
+
ts: now.toISOString(),
|
|
152
|
+
level: eventLevel(event),
|
|
153
|
+
category: event.category,
|
|
154
|
+
op: redactLogLabel(event.op),
|
|
155
|
+
};
|
|
156
|
+
const extra = redactLogFields(event.extra);
|
|
157
|
+
if (extra !== undefined)
|
|
158
|
+
Object.assign(record, extra);
|
|
159
|
+
applyEnvelopeFields(record, event);
|
|
160
|
+
const line = `${JSON.stringify(record)}\n`;
|
|
161
|
+
// One byte measurement on the happy path; the second only on the line that is being replaced.
|
|
162
|
+
return serverLogLineWithinCap(line) ? line : oversizedLine(record, serverLogLineBytes(line));
|
|
163
|
+
}
|
|
164
|
+
// The cap is a cap on BYTES, because the write below encodes UTF-8 and a log shipper's line limit
|
|
165
|
+
// counts bytes. `line.length` counts UTF-16 code units, so comparing it against the cap admitted a
|
|
166
|
+
// line up to three times the stated size — and multi-byte text is exactly what makes a line
|
|
167
|
+
// oversized in the first place, since a document body is the only thing that gets there.
|
|
168
|
+
//
|
|
169
|
+
// The value guards in `log-redaction.ts` currently refuse a non-ASCII field value outright, so in
|
|
170
|
+
// today's wiring the two counts agree. That is a second layer, not a reason to measure the wrong
|
|
171
|
+
// thing here: this module's cap must hold on its own for whatever a future producer, or a relaxed
|
|
172
|
+
// value guard, puts on a line.
|
|
173
|
+
export function serverLogLineBytes(line) {
|
|
174
|
+
return Buffer.byteLength(line, "utf8");
|
|
175
|
+
}
|
|
176
|
+
export function serverLogLineWithinCap(line) {
|
|
177
|
+
return serverLogLineBytes(line) <= MAX_LOG_LINE_BYTES;
|
|
178
|
+
}
|
|
179
|
+
function oversizedLine(record, lineBytes) {
|
|
180
|
+
const replacement = {
|
|
181
|
+
ts: record.ts,
|
|
182
|
+
level: record.level,
|
|
183
|
+
category: record.category,
|
|
184
|
+
op: record.op,
|
|
185
|
+
errorKind: "log-line-oversized",
|
|
186
|
+
droppedLineBytes: lineBytes,
|
|
187
|
+
};
|
|
188
|
+
return `${JSON.stringify(replacement)}\n`;
|
|
189
|
+
}
|
|
190
|
+
function todayUtc(now = new Date()) {
|
|
191
|
+
return now.toISOString().slice(0, 10);
|
|
192
|
+
}
|
|
193
|
+
function closeHandle(active) {
|
|
194
|
+
if (active.handle === null)
|
|
195
|
+
return;
|
|
196
|
+
try {
|
|
197
|
+
closeSync(active.handle);
|
|
198
|
+
}
|
|
199
|
+
catch {
|
|
200
|
+
// A descriptor we can no longer close is a descriptor we must stop using either way.
|
|
201
|
+
}
|
|
202
|
+
active.handle = null;
|
|
203
|
+
}
|
|
204
|
+
// Throws rather than returning null: a descriptor we cannot open is a failure an operator has to
|
|
205
|
+
// hear about, and the caller's catch is the one place that both closes and reports.
|
|
206
|
+
function ensureHandle(active) {
|
|
207
|
+
if (active.handle !== null)
|
|
208
|
+
return active.handle;
|
|
209
|
+
active.handle = openSync(active.currentPath, "a", 0o600);
|
|
210
|
+
return active.handle;
|
|
211
|
+
}
|
|
212
|
+
function errorCode(error) {
|
|
213
|
+
if (typeof error !== "object" || error === null || !("code" in error))
|
|
214
|
+
return "";
|
|
215
|
+
const { code } = error;
|
|
216
|
+
return typeof code === "string" ? code : "";
|
|
217
|
+
}
|
|
218
|
+
// Names old files with their calendar day, e.g. `server-2026-08-20.log`, and keeps at most
|
|
219
|
+
// `retentionDays` of them. A fresh install starts empty. This is the whole rotation policy.
|
|
220
|
+
function rotateIfNeeded(active) {
|
|
221
|
+
const day = todayUtc();
|
|
222
|
+
if (day === active.currentDay)
|
|
223
|
+
return;
|
|
224
|
+
closeHandle(active);
|
|
225
|
+
// A successful archive means the file we were mid-record in is no longer the file we append to,
|
|
226
|
+
// so the partial-record debt does not travel to the fresh one.
|
|
227
|
+
if (archiveCurrentDay(active))
|
|
228
|
+
active.pendingNewline = false;
|
|
229
|
+
active.currentDay = day;
|
|
230
|
+
pruneOldFiles(active.directory, active.retentionDays);
|
|
231
|
+
}
|
|
232
|
+
// Rotation has to be atomic ACROSS PROCESSES, not merely within one. `renameSync` REPLACES an
|
|
233
|
+
// existing destination, so two Keiko processes sharing a state directory that both reach the UTC
|
|
234
|
+
// boundary destroy the finished day: the first archives it, the second renames its own fresh file
|
|
235
|
+
// over that archive. An `existsSync` guard does not close that window — it is a check, and the
|
|
236
|
+
// window is between the check and the rename. The in-process registry below cannot help either;
|
|
237
|
+
// by construction it coordinates only one process.
|
|
238
|
+
//
|
|
239
|
+
// `link(2)` has no such window: it fails with EEXIST when the destination already exists, so
|
|
240
|
+
// exactly one process can ever create `server-<day>.log`. The loser leaves the archive alone and
|
|
241
|
+
// only advances its own day; only the winner unlinks the current path, so a fresh file another
|
|
242
|
+
// process is already appending to can never be moved on top of a finished day.
|
|
243
|
+
// `link(2)` reports "not supported by this filesystem" through these. EPERM is ambiguous — it is
|
|
244
|
+
// also plain permission denial — but the state directory is created by this process at 0700, so a
|
|
245
|
+
// permission failure on it is not the reachable case, and treating it as unsupported keeps
|
|
246
|
+
// removable-media installs rotating.
|
|
247
|
+
const NO_HARD_LINK_SUPPORT = new Set(["EPERM", "ENOSYS", "EOPNOTSUPP", "ENOTSUP"]);
|
|
248
|
+
function archiveCurrentDay(active) {
|
|
249
|
+
const rolled = join(active.directory, `server-${active.currentDay}.log`);
|
|
250
|
+
try {
|
|
251
|
+
linkSync(active.currentPath, rolled);
|
|
252
|
+
}
|
|
253
|
+
catch (error) {
|
|
254
|
+
const code = errorCode(error);
|
|
255
|
+
// EEXIST: a peer already archived this day, and leaving its file untouched is the whole point.
|
|
256
|
+
// ENOENT: there is nothing to archive (a fresh install, or a peer that has already moved it).
|
|
257
|
+
if (code === "EEXIST" || code === "ENOENT")
|
|
258
|
+
return false;
|
|
259
|
+
// ONLY "this filesystem has no hard links" may fall back to the destination-replacing rename.
|
|
260
|
+
// EACCES, EMLINK, EIO and friends are real failures, and for them the safe outcome is to NOT
|
|
261
|
+
// rotate: one file growing is a nuisance, overwriting a peer's finished archive is data loss.
|
|
262
|
+
// Choose the nuisance. Without this narrowing the fallback re-opened the exact race the
|
|
263
|
+
// hard-link rotation exists to close.
|
|
264
|
+
if (!NO_HARD_LINK_SUPPORT.has(code))
|
|
265
|
+
return false;
|
|
266
|
+
return archiveWithoutHardLinks(active, rolled);
|
|
267
|
+
}
|
|
268
|
+
return unlinkCurrentPath(active);
|
|
269
|
+
}
|
|
270
|
+
// A filesystem that cannot hard-link at all (FAT/exFAT under a state directory on removable
|
|
271
|
+
// media). No atomic primitive is left, so this falls back to the guarded rename rather than never
|
|
272
|
+
// rotating and letting one file grow without bound — the cross-process window exists only here,
|
|
273
|
+
// and only where nothing better is available.
|
|
274
|
+
function archiveWithoutHardLinks(active, rolled) {
|
|
275
|
+
if (existsSync(rolled) || !existsSync(active.currentPath))
|
|
276
|
+
return false;
|
|
277
|
+
try {
|
|
278
|
+
renameSync(active.currentPath, rolled);
|
|
279
|
+
return true;
|
|
280
|
+
}
|
|
281
|
+
catch {
|
|
282
|
+
// Windows file-busy and friends: keep appending to the current file — rotation is a
|
|
283
|
+
// convenience, not a correctness requirement.
|
|
284
|
+
return false;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
function unlinkCurrentPath(active) {
|
|
288
|
+
try {
|
|
289
|
+
unlinkSync(active.currentPath);
|
|
290
|
+
return true;
|
|
291
|
+
}
|
|
292
|
+
catch {
|
|
293
|
+
// The archive is written, which is the part that matters. This process keeps appending to the
|
|
294
|
+
// still-linked current file, and the next boundary finds the archive present and leaves it be.
|
|
295
|
+
return false;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
function pruneOldFiles(directory, retentionDays) {
|
|
299
|
+
try {
|
|
300
|
+
const entries = readdirSync(directory).filter((name) => /^server-\d{4}-\d{2}-\d{2}\.log$/.test(name));
|
|
301
|
+
if (entries.length <= retentionDays)
|
|
302
|
+
return;
|
|
303
|
+
// Explicit collator, not the default lexicographic sort: the names are ISO-dated, so the
|
|
304
|
+
// ordering decides which files rotation deletes.
|
|
305
|
+
entries.sort((left, right) => left.localeCompare(right, "en-US"));
|
|
306
|
+
for (const stale of entries.slice(0, entries.length - retentionDays)) {
|
|
307
|
+
try {
|
|
308
|
+
unlinkSync(join(directory, stale));
|
|
309
|
+
}
|
|
310
|
+
catch {
|
|
311
|
+
// Best effort; a locked file will be retried on the next rotation.
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
catch {
|
|
316
|
+
// Directory unreadable is not a reason to fail the server; the next write recreates it.
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
// The descriptor is opened `a`, so every write is an atomic O_APPEND write at the current end of
|
|
320
|
+
// file. Inside one process the registry above already gives every sink on a file the same
|
|
321
|
+
// descriptor; O_APPEND is what additionally makes it safe for a SECOND Keiko process sharing the
|
|
322
|
+
// same state directory, which no in-process registry can coordinate. `writeSync` may still report
|
|
323
|
+
// a short write, so loop until the whole line has landed.
|
|
324
|
+
//
|
|
325
|
+
// A descriptor that reports ZERO bytes has stopped accepting them: looping would spin, and simply
|
|
326
|
+
// returning would leave a partial JSON record behind whose bytes then merge with the NEXT record —
|
|
327
|
+
// one stalled line silently costing two, and a reader that splits on newlines losing both. So the
|
|
328
|
+
// stall throws: the caller closes the descriptor, and the line is dropped. A dropped line is the
|
|
329
|
+
// honest outcome; a truncated one is not, because it damages a record that was never in trouble.
|
|
330
|
+
function writeAll(handle, payload) {
|
|
331
|
+
let offset = 0;
|
|
332
|
+
while (offset < payload.length) {
|
|
333
|
+
const written = writeSync(handle, payload, offset, payload.length - offset);
|
|
334
|
+
if (written <= 0)
|
|
335
|
+
throw new Error("activity log descriptor accepted no bytes");
|
|
336
|
+
offset += written;
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
// The bytes a stalled write already handed to the kernel cannot be recalled, so the damage is
|
|
340
|
+
// bounded from the other side: the ActiveLog remembers that the file ends mid-record and the next
|
|
341
|
+
// record opens with a newline. That is deterministic — unlike writing a terminator, which asks a
|
|
342
|
+
// descriptor that is refusing bytes to accept one more.
|
|
343
|
+
function writeRecord(active, handle, line) {
|
|
344
|
+
const payload = Buffer.from(active.pendingNewline ? `\n${line}` : line, "utf8");
|
|
345
|
+
// Cleared only once the whole record has landed; a throw from `writeAll` leaves it set.
|
|
346
|
+
active.pendingNewline = true;
|
|
347
|
+
writeAll(handle, payload);
|
|
348
|
+
active.pendingNewline = false;
|
|
349
|
+
}
|
|
350
|
+
// The process-wide registry that makes the file sink a singleton per resolved log directory. Every
|
|
351
|
+
// consumer of the same file shares one descriptor and one rotation state; the threshold stays
|
|
352
|
+
// per-consumer, because that is a caller's own volume control and cannot lose data.
|
|
353
|
+
const activeLogs = new Map();
|
|
354
|
+
function resolveActiveLog(directory, retentionDays) {
|
|
355
|
+
const key = resolvePath(directory);
|
|
356
|
+
const existing = activeLogs.get(key);
|
|
357
|
+
// The first caller's retention wins: a second sink on the same file is the same file, and two
|
|
358
|
+
// retention policies over one directory is not a thing that can be honoured anyway.
|
|
359
|
+
if (existing !== undefined)
|
|
360
|
+
return existing;
|
|
361
|
+
const created = {
|
|
362
|
+
directory,
|
|
363
|
+
currentPath: join(directory, "server.log"),
|
|
364
|
+
retentionDays,
|
|
365
|
+
currentDay: todayUtc(),
|
|
366
|
+
handle: null,
|
|
367
|
+
pendingNewline: false,
|
|
368
|
+
};
|
|
369
|
+
activeLogs.set(key, created);
|
|
370
|
+
return created;
|
|
371
|
+
}
|
|
372
|
+
// Closes every open activity-log descriptor. Called by the server logger's shutdown/reset path,
|
|
373
|
+
// and by tests so a suite does not leave descriptors behind. A subsequent write reopens: closing
|
|
374
|
+
// releases an OS resource, it never disables the log.
|
|
375
|
+
//
|
|
376
|
+
// The registry entries themselves are KEPT. Dropping them would let a sink created after a
|
|
377
|
+
// shutdown build a second ActiveLog over a file some retained sink still writes to — which is the
|
|
378
|
+
// two-rotation-states data loss this registry exists to make impossible.
|
|
379
|
+
export function closeFileServerLogSinks() {
|
|
380
|
+
for (const active of activeLogs.values())
|
|
381
|
+
closeHandle(active);
|
|
382
|
+
}
|
|
383
|
+
export function createFileServerLogSink(stateDir, options = {}) {
|
|
384
|
+
const directory = join(stateDir, "logs");
|
|
385
|
+
try {
|
|
386
|
+
mkdirSync(directory, { recursive: true, mode: 0o700 });
|
|
387
|
+
}
|
|
388
|
+
catch {
|
|
389
|
+
// If we cannot create the directory we return a null sink rather than crashing the
|
|
390
|
+
// server; the caller keeps running and the operator sees a missing file, not a hang.
|
|
391
|
+
return NULL_SINK;
|
|
392
|
+
}
|
|
393
|
+
const active = resolveActiveLog(directory, options.retentionDays ?? DEFAULT_LOG_RETENTION_DAYS);
|
|
394
|
+
const threshold = options.level ?? resolveServerLogThreshold(options.env ?? process.env);
|
|
395
|
+
return createFileSinkFacade(active, threshold);
|
|
396
|
+
}
|
|
397
|
+
// Split out so `createFileServerLogSink` stays inside the 50-line ceiling.
|
|
398
|
+
function createFileSinkFacade(active, threshold) {
|
|
399
|
+
return {
|
|
400
|
+
write(event) {
|
|
401
|
+
// The threshold check comes before any formatting: a filtered event costs one comparison.
|
|
402
|
+
if (!serverLogLevelEnabled(eventLevel(event), threshold))
|
|
403
|
+
return;
|
|
404
|
+
try {
|
|
405
|
+
rotateIfNeeded(active);
|
|
406
|
+
writeRecord(active, ensureHandle(active), formatServerLogLine(event));
|
|
407
|
+
}
|
|
408
|
+
catch (error) {
|
|
409
|
+
// Writing must never take the server down; a full disk, a permission change or a file
|
|
410
|
+
// removed under us drops the line and forces a reopen on the next write. It does NOT drop
|
|
411
|
+
// the fact that it happened: a log that has stopped working is exactly the condition an
|
|
412
|
+
// operator cannot infer from the absence of lines.
|
|
413
|
+
closeHandle(active);
|
|
414
|
+
reportServerLogFailure(error, { op: event.op, correlationId: event.correlationId });
|
|
415
|
+
}
|
|
416
|
+
},
|
|
417
|
+
flush() {
|
|
418
|
+
// `writeSync` leaves nothing in user space, so a flush is already complete on return.
|
|
419
|
+
},
|
|
420
|
+
close() {
|
|
421
|
+
// The descriptor belongs to the shared ActiveLog, so this releases it for every sink on the
|
|
422
|
+
// file. That is correct for a shutdown path and harmless otherwise: the next write reopens.
|
|
423
|
+
closeHandle(active);
|
|
424
|
+
},
|
|
425
|
+
};
|
|
426
|
+
}
|
|
427
|
+
// Test-only helper: buffered sink that keeps every event in memory so tests can assert on
|
|
428
|
+
// order and content without touching the filesystem. It captures RAW events and applies no
|
|
429
|
+
// threshold of its own, so a test can tell "the logger filtered this" from "the sink did".
|
|
430
|
+
//
|
|
431
|
+
// "Test-only" is enforced by where it is reachable from, not by the comment: it is exported from
|
|
432
|
+
// this module and from the in-package `observability/` barrel that every keiko-server test imports,
|
|
433
|
+
// and deliberately NOT from the package's public entry point. Nothing outside this package has a
|
|
434
|
+
// use for it, and a packaged export is a promise that has to be kept.
|
|
435
|
+
export function createBufferedServerLogSink() {
|
|
436
|
+
const events = [];
|
|
437
|
+
return {
|
|
438
|
+
events,
|
|
439
|
+
write(event) {
|
|
440
|
+
events.push(event);
|
|
441
|
+
},
|
|
442
|
+
lines() {
|
|
443
|
+
return events.map((event) => formatServerLogLine(event));
|
|
444
|
+
},
|
|
445
|
+
clear() {
|
|
446
|
+
events.length = 0;
|
|
447
|
+
},
|
|
448
|
+
};
|
|
449
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { ServerLogLevel, ServerLogThreshold } from "./log-level.js";
|
|
2
|
+
import type { ServerLogCategory, ServerLogSink } from "./server-log.js";
|
|
3
|
+
export type ServerLogContext = Readonly<Record<string, unknown>>;
|
|
4
|
+
export interface ServerLogEventInput {
|
|
5
|
+
readonly category?: ServerLogCategory | undefined;
|
|
6
|
+
readonly op: string;
|
|
7
|
+
readonly correlationId?: string | undefined;
|
|
8
|
+
readonly durationMs?: number | undefined;
|
|
9
|
+
readonly status?: number | undefined;
|
|
10
|
+
readonly errorKind?: string | undefined;
|
|
11
|
+
readonly extra?: Readonly<Record<string, unknown>> | undefined;
|
|
12
|
+
}
|
|
13
|
+
export type ServerLogEventSource = ServerLogEventInput | (() => ServerLogEventInput);
|
|
14
|
+
export interface ServerLogger {
|
|
15
|
+
readonly level: ServerLogThreshold;
|
|
16
|
+
readonly isLevelEnabled: (level: ServerLogLevel) => boolean;
|
|
17
|
+
readonly debug: (source: ServerLogEventSource) => void;
|
|
18
|
+
readonly info: (source: ServerLogEventSource) => void;
|
|
19
|
+
readonly warn: (source: ServerLogEventSource) => void;
|
|
20
|
+
readonly error: (source: ServerLogEventSource) => void;
|
|
21
|
+
readonly log: (level: ServerLogLevel, source: ServerLogEventSource) => void;
|
|
22
|
+
readonly child: (context: ServerLogContext) => ServerLogger;
|
|
23
|
+
}
|
|
24
|
+
export interface ServerLoggerOptions {
|
|
25
|
+
readonly sink: ServerLogSink;
|
|
26
|
+
readonly level?: ServerLogThreshold | undefined;
|
|
27
|
+
readonly context?: ServerLogContext | undefined;
|
|
28
|
+
}
|
|
29
|
+
export declare function createServerLogger(options: ServerLoggerOptions): ServerLogger;
|
|
30
|
+
export declare function nullServerLogger(): ServerLogger;
|
|
31
|
+
export declare function startLogTimer(): () => number;
|
|
32
|
+
export declare function getServerLogger(): ServerLogger;
|
|
33
|
+
export declare function setServerLogger(logger: ServerLogger): void;
|
|
34
|
+
export declare function shutdownServerLogging(): void;
|
|
35
|
+
export declare function resetServerLogger(): void;
|
|
36
|
+
//# sourceMappingURL=server-logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server-logger.d.ts","sourceRoot":"","sources":["../../src/observability/server-logger.ts"],"names":[],"mappings":"AA6BA,OAAO,KAAK,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAQzE,OAAO,KAAK,EACV,iBAAiB,EAGjB,aAAa,EACd,MAAM,iBAAiB,CAAC;AAIzB,MAAM,MAAM,gBAAgB,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;AAIjE,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,QAAQ,CAAC,EAAE,iBAAiB,GAAG,SAAS,CAAC;IAClD,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5C,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACzC,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACrC,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACxC,QAAQ,CAAC,KAAK,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC;CAChE;AAGD,MAAM,MAAM,oBAAoB,GAAG,mBAAmB,GAAG,CAAC,MAAM,mBAAmB,CAAC,CAAC;AAErF,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,KAAK,EAAE,kBAAkB,CAAC;IACnC,QAAQ,CAAC,cAAc,EAAE,CAAC,KAAK,EAAE,cAAc,KAAK,OAAO,CAAC;IAC5D,QAAQ,CAAC,KAAK,EAAE,CAAC,MAAM,EAAE,oBAAoB,KAAK,IAAI,CAAC;IACvD,QAAQ,CAAC,IAAI,EAAE,CAAC,MAAM,EAAE,oBAAoB,KAAK,IAAI,CAAC;IACtD,QAAQ,CAAC,IAAI,EAAE,CAAC,MAAM,EAAE,oBAAoB,KAAK,IAAI,CAAC;IACtD,QAAQ,CAAC,KAAK,EAAE,CAAC,MAAM,EAAE,oBAAoB,KAAK,IAAI,CAAC;IACvD,QAAQ,CAAC,GAAG,EAAE,CAAC,KAAK,EAAE,cAAc,EAAE,MAAM,EAAE,oBAAoB,KAAK,IAAI,CAAC;IAC5E,QAAQ,CAAC,KAAK,EAAE,CAAC,OAAO,EAAE,gBAAgB,KAAK,YAAY,CAAC;CAC7D;AA2ED,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAC;IAC7B,QAAQ,CAAC,KAAK,CAAC,EAAE,kBAAkB,GAAG,SAAS,CAAC;IAChD,QAAQ,CAAC,OAAO,CAAC,EAAE,gBAAgB,GAAG,SAAS,CAAC;CACjD;AAED,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,mBAAmB,GAAG,YAAY,CAK7E;AA0DD,wBAAgB,gBAAgB,IAAI,YAAY,CAE/C;AAID,wBAAgB,aAAa,IAAI,MAAM,MAAM,CAG5C;AAqBD,wBAAgB,eAAe,IAAI,YAAY,CAG9C;AAGD,wBAAgB,eAAe,CAAC,MAAM,EAAE,YAAY,GAAG,IAAI,CAE1D;AAOD,wBAAgB,qBAAqB,IAAI,IAAI,CAM5C;AAID,wBAAgB,iBAAiB,IAAI,IAAI,CAExC"}
|