@kindgi/log 0.0.0-bootstrap.0 → 0.1.4-rc.5

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/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for describing the origin of the Work and
141
+ reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 Kindgi Inc.
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,84 @@
1
+ # `@kindgi/log`
2
+
3
+ Kindgi's structured logger. The runtime and `@kindgi/api` (`createApp({ logger })`) write the same records, so `kindgi dev`, Cloud Logging, Datadog or Loki read them the same way. Zero runtime dependencies.
4
+
5
+ - **Levels per subsystem:** `error`, `warn`, `info`, `debug` and `trace`, set per subsystem. A dotted name inherits its parent's level, so `kernel=debug` covers `kernel.sweeper`.
6
+ - **Two formats:**
7
+ - **JSON:** one record per line, for collectors.
8
+ - **Pretty:** for a person at a terminal.
9
+ - **Redaction:** applied to every record before it's written, at every level.
10
+ - **W3C Trace Context helpers:** they carry a caller's trace id through a request, a run, and the calls they make.
11
+
12
+ ## Use
13
+
14
+ ```ts
15
+ import { createLogger } from '@kindgi/log';
16
+
17
+ const log = createLogger({ level: 'info', format: 'json', write: (line) => process.stdout.write(`${line}\n`) });
18
+
19
+ const leases = log.child({ subsystem: 'leases' });
20
+ leases.warn('could not expire the lease of run r-1', { runId: 'r-1', err });
21
+ ```
22
+
23
+ ```json
24
+ {"time":"2026-10-07T21:58:03.120Z","level":"warn","severity":"WARNING","subsystem":"leases","message":"could not expire the lease of run r-1","runId":"r-1","err":{"name":"Error","message":"…"}}
25
+ ```
26
+
27
+ - **Every record has five fields:** `time` (RFC 3339), `level`, `severity`, `subsystem` and `message`.
28
+ - `severity` is Cloud Logging's name for the level (`ERROR`, `WARNING`, `INFO`, `DEBUG`), so Cloud Run and GKE show levels with no agent configuration.
29
+ - Records without a subsystem are `root`.
30
+ - **Correlation ids come next,** when known: `traceId`, `spanId`, `requestId`, `tenantId`, `projectId`, `runId`, `agentId`, `toolId`, and others. Then the event's own fields.
31
+ - **Pass an error as `{ err: error }`:** it's written as `name`, `message` and `code`. The `stack` is added at `error` level, or when the logger is at `debug` or below.
32
+ - **`child(bindings)`** returns a logger whose records all carry the bindings. A child's `subsystem` replaces its parent's, so name it in full (`kernel.sweeper`).
33
+ - **`isLevelEnabled(level)`** says whether a record would be written, so you can skip building costly fields.
34
+ - **`{ inMessage: [...] }`, a third argument,** names the fields the message already states: `log.info('GET /v1/runs 200 12ms', { method, route, status, durationMs }, { inMessage: ['method', 'route', 'status', 'durationMs'] })`. The pretty format leaves them out; JSON keeps every field.
35
+ - **`noopLogger`** writes nothing. It's the default where a logger isn't given.
36
+ - **Logging never throws.** A sink that fails is ignored.
37
+
38
+ ## Configuration: `loggerFromEnv`
39
+
40
+ ```ts
41
+ import { loggerFromEnv } from '@kindgi/log';
42
+
43
+ const got = loggerFromEnv({ env: process.env, isTTY: process.stdout.isTTY === true, subsystems: ['http', 'kernel'] });
44
+ if (got.kind === 'err') {
45
+ console.error(got.message);
46
+ process.exit(2);
47
+ }
48
+ for (const problem of got.problems) got.logger.warn(problem);
49
+ ```
50
+
51
+ | Variable | Values | Default |
52
+ |---|---|---|
53
+ | `KINDGI_LOG_LEVEL` | `error` `warn` `info` `debug` `trace` | `info` |
54
+ | `KINDGI_LOG_LEVELS` | `subsystem=level`, comma-separated: `kernel=debug,http=warn` | none |
55
+ | `KINDGI_LOG_FORMAT` | `auto` `json` `pretty` | `auto`: pretty on a terminal or with `KINDGI_DEV=true`, JSON otherwise |
56
+
57
+ - **What refuses to start:** an unknown level or format, or a malformed `KINDGI_LOG_LEVELS`.
58
+ - **What only warns:** a subsystem no code logs under. It's returned in `problems`, so a typo doesn't stop a server.
59
+ - **Colours:** used in the pretty format on a terminal, unless `NO_COLOR` is set.
60
+
61
+ ## Redaction
62
+
63
+ 1. **Keys.** A field whose key looks secret is written as `[redacted]`, at any depth. A key looks secret when, lowercased and without `-` or `_`, it ends with `authorization`, `cookie`, `token`, `password`, `secret(s)`, `apikey`, `privatekey`, `passphrase` or `credential(s)`; `redact` adds your own. So `accessToken` and `x-api-key` are redacted, and `promptTokens` and `secretRef` aren't.
64
+ 2. **Values.** Every string (the message, the fields, an error's message and stack) is scrubbed of known shapes only:
65
+ - a Kindgi token (`kgi_bt_…`) keeps its prefix and last four characters;
66
+ - `Bearer <anything>` becomes `Bearer [redacted]`;
67
+ - a URL's password (`postgres://user:pass@`) becomes `user:***@`.
68
+
69
+ Ids are never touched: the scrubber only matches exact patterns, and doesn't guess at entropy.
70
+
71
+ Pass a secret's *name*, never its value: redaction is the safety net, not the rule.
72
+
73
+ ## Trace context
74
+
75
+ ```ts
76
+ import { formatTraceparent, traceFromHeader } from '@kindgi/log';
77
+
78
+ const trace = traceFromHeader(request.headers.get('traceparent'));
79
+ log.child({ traceId: trace.traceId, spanId: trace.spanId }).info('handling');
80
+ response.headers.set('traceresponse', formatTraceparent(trace));
81
+ ```
82
+
83
+ - **`traceFromHeader`** continues the caller's trace when its `traceparent` is valid, with a new span whose parent is the caller's. A missing or malformed header starts a fresh trace.
84
+ - **`parseTraceparent`, `newTraceContext`, `childSpan` and `formatTraceparent`** are the pieces it's built from, as pure functions on Web Crypto.
package/dist/env.d.ts ADDED
@@ -0,0 +1,40 @@
1
+ import type { LogFormat, Logger } from './types.js';
2
+ /**
3
+ * `KINDGI_LOG_FORMAT`'s value as a format: `json` or `pretty` as given;
4
+ * `auto` (the default) is pretty on a terminal or in development mode
5
+ * (`dev`: `KINDGI_DEV`, which every `kindgi dev` sets, so an older CLI that
6
+ * passes no format still shows pretty lines), and JSON otherwise. So the
7
+ * CLI and the runtime agree. `undefined` for any other
8
+ * value.
9
+ */
10
+ export declare function resolveLogFormat(raw: string | undefined, context: {
11
+ readonly isTTY: boolean;
12
+ readonly dev?: boolean;
13
+ }): LogFormat | undefined;
14
+ export type LoggerFromEnv = {
15
+ readonly kind: 'ok';
16
+ readonly logger: Logger;
17
+ /** Settings that are wrong but harmless: log them at boot (an unknown subsystem, say). */
18
+ readonly problems: readonly string[];
19
+ } | {
20
+ /** A setting that can't be honoured: refuse to start, naming it (exit code 2). */
21
+ readonly kind: 'err';
22
+ readonly message: string;
23
+ };
24
+ /**
25
+ * The root logger from `KINDGI_LOG_LEVEL`, `KINDGI_LOG_LEVELS` and
26
+ * `KINDGI_LOG_FORMAT`. An unknown level or format, or a malformed
27
+ * `KINDGI_LOG_LEVELS`, is an error; a subsystem not in `subsystems` (when
28
+ * given) is a problem to report, not a refusal, so a typo doesn't stop a
29
+ * server. Default sink: stdout.
30
+ */
31
+ export declare function loggerFromEnv(input: {
32
+ readonly env: Readonly<Record<string, string | undefined>>;
33
+ readonly write?: (line: string) => void;
34
+ readonly isTTY?: boolean;
35
+ /** The subsystems the caller logs under, to flag an unknown one. */
36
+ readonly subsystems?: readonly string[];
37
+ /** Extra field keys to redact. */
38
+ readonly redact?: readonly string[];
39
+ }): LoggerFromEnv;
40
+ //# sourceMappingURL=env.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../src/env.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAEpD;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAC9B,GAAG,EAAE,MAAM,GAAG,SAAS,EACvB,OAAO,EAAE;IAAE,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,OAAO,CAAA;CAAE,GAC3D,SAAS,GAAG,SAAS,CAOvB;AA6BD,MAAM,MAAM,aAAa,GACrB;IACE,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC;IACpB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,0FAA0F;IAC1F,QAAQ,CAAC,QAAQ,EAAE,SAAS,MAAM,EAAE,CAAC;CACtC,GACD;IACE,kFAAkF;IAClF,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC;IACrB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B,CAAC;AAEN;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE;IACnC,QAAQ,CAAC,GAAG,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC,CAAC;IAC3D,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IACxC,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC;IACzB,oEAAoE;IACpE,QAAQ,CAAC,UAAU,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACxC,kCAAkC;IAClC,QAAQ,CAAC,MAAM,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CACrC,GAAG,aAAa,CAiChB"}
package/dist/env.js ADDED
@@ -0,0 +1,82 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ // Copyright (C) 2026 Kindgi Inc.
3
+ import { LOG_LEVELS, parseLogLevel, parseLogLevels } from './levels.js';
4
+ import { createLogger } from './logger.js';
5
+ /**
6
+ * `KINDGI_LOG_FORMAT`'s value as a format: `json` or `pretty` as given;
7
+ * `auto` (the default) is pretty on a terminal or in development mode
8
+ * (`dev`: `KINDGI_DEV`, which every `kindgi dev` sets, so an older CLI that
9
+ * passes no format still shows pretty lines), and JSON otherwise. So the
10
+ * CLI and the runtime agree. `undefined` for any other
11
+ * value.
12
+ */
13
+ export function resolveLogFormat(raw, context) {
14
+ const value = (raw ?? '').trim().toLowerCase();
15
+ if (value === '' || value === 'auto') {
16
+ return context.isTTY || context.dev === true ? 'pretty' : 'json';
17
+ }
18
+ if (value === 'json' || value === 'pretty')
19
+ return value;
20
+ return undefined;
21
+ }
22
+ /** `KINDGI_LOG_LEVEL`'s level (`info` when unset), or the error that names a bad one. */
23
+ function levelFromEnv(raw) {
24
+ if (raw === undefined || raw.trim() === '')
25
+ return 'info';
26
+ const parsed = parseLogLevel(raw);
27
+ if (parsed !== undefined)
28
+ return parsed;
29
+ return {
30
+ kind: 'err',
31
+ message: `KINDGI_LOG_LEVEL must be one of ${LOG_LEVELS.join(', ')}, got "${raw}".`,
32
+ };
33
+ }
34
+ /** `KINDGI_LOG_LEVELS` entries no subsystem logs under (nor its dotted root). */
35
+ function unknownSubsystems(levels, subsystems) {
36
+ const known = new Set(subsystems);
37
+ return Object.keys(levels)
38
+ .filter((name) => !known.has(name) && !known.has(name.split('.')[0] ?? name))
39
+ .map((name) => `KINDGI_LOG_LEVELS names "${name}", which no subsystem logs under; it has no effect.`);
40
+ }
41
+ /**
42
+ * The root logger from `KINDGI_LOG_LEVEL`, `KINDGI_LOG_LEVELS` and
43
+ * `KINDGI_LOG_FORMAT`. An unknown level or format, or a malformed
44
+ * `KINDGI_LOG_LEVELS`, is an error; a subsystem not in `subsystems` (when
45
+ * given) is a problem to report, not a refusal, so a typo doesn't stop a
46
+ * server. Default sink: stdout.
47
+ */
48
+ export function loggerFromEnv(input) {
49
+ const { env } = input;
50
+ const level = levelFromEnv(env.KINDGI_LOG_LEVEL);
51
+ if (typeof level === 'object')
52
+ return level;
53
+ const levels = parseLogLevels(env.KINDGI_LOG_LEVELS ?? '');
54
+ if (levels.kind === 'err') {
55
+ return { kind: 'err', message: `KINDGI_LOG_LEVELS: ${levels.message}.` };
56
+ }
57
+ const isTTY = input.isTTY ?? false;
58
+ const dev = ['true', '1'].includes((env.KINDGI_DEV ?? '').trim().toLowerCase());
59
+ const format = resolveLogFormat(env.KINDGI_LOG_FORMAT, { isTTY, dev });
60
+ if (format === undefined) {
61
+ return {
62
+ kind: 'err',
63
+ message: `KINDGI_LOG_FORMAT must be auto, json or pretty, got "${env.KINDGI_LOG_FORMAT}".`,
64
+ };
65
+ }
66
+ const problems = input.subsystems === undefined ? [] : unknownSubsystems(levels.levels, input.subsystems);
67
+ const write = input.write ??
68
+ ((line) => {
69
+ if (typeof process !== 'undefined')
70
+ process.stdout.write(`${line}\n`);
71
+ });
72
+ const logger = createLogger({
73
+ level,
74
+ levels: levels.levels,
75
+ format,
76
+ color: format === 'pretty' && isTTY && (env.NO_COLOR ?? '') === '',
77
+ write,
78
+ ...(input.redact !== undefined && { redact: input.redact }),
79
+ });
80
+ return { kind: 'ok', logger, problems };
81
+ }
82
+ //# sourceMappingURL=env.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"env.js","sourceRoot":"","sources":["../src/env.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,iCAAiC;AAEjC,OAAO,EAAE,UAAU,EAAiB,aAAa,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AACvF,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAG3C;;;;;;;GAOG;AACH,MAAM,UAAU,gBAAgB,CAC9B,GAAuB,EACvB,OAA4D;IAE5D,MAAM,KAAK,GAAG,CAAC,GAAG,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;IAC/C,IAAI,KAAK,KAAK,EAAE,IAAI,KAAK,KAAK,MAAM,EAAE,CAAC;QACrC,OAAO,OAAO,CAAC,KAAK,IAAI,OAAO,CAAC,GAAG,KAAK,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC;IACnE,CAAC;IACD,IAAI,KAAK,KAAK,MAAM,IAAI,KAAK,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IACzD,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,yFAAyF;AACzF,SAAS,YAAY,CACnB,GAAuB;IAEvB,IAAI,GAAG,KAAK,SAAS,IAAI,GAAG,CAAC,IAAI,EAAE,KAAK,EAAE;QAAE,OAAO,MAAM,CAAC;IAC1D,MAAM,MAAM,GAAG,aAAa,CAAC,GAAG,CAAC,CAAC;IAClC,IAAI,MAAM,KAAK,SAAS;QAAE,OAAO,MAAM,CAAC;IACxC,OAAO;QACL,IAAI,EAAE,KAAK;QACX,OAAO,EAAE,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AC,WAAW,EAAE,CAAC,CAAC;IAChF,MAAM,MAAM,GAAG,gBAAgB,CAAC,GAAG,CAAC,iBAAiB,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,CAAC;IACvE,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;QACzB,OAAO;YACL,IAAI,EAAE,KAAK;YACX,OAAO,EAAE,wDAAwD,GAAG,CAAC,iBAAiB,IAAI;SAC3F,CAAC;IACJ,CAAC;IACD,MAAM,QAAQ,GACZ,KAAK,CAAC,UAAU,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,iBAAiB,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC;IAC3F,MAAM,KAAK,GACT,KAAK,CAAC,KAAK;QACX,CAAC,CAAC,IAAY,EAAE,EAAE;YAChB,IAAI,OAAO,OAAO,KAAK,WAAW;gBAAE,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,IAAI,IAAI,CAAC,CAAC;QACxE,CAAC,CAAC,CAAC;IACL,MAAM,MAAM,GAAG,YAAY,CAAC;QAC1B,KAAK;QACL,MAAM,EAAE,MAAM,CAAC,MAAM;QACrB,MAAM;QACN,KAAK,EAAE,MAAM,KAAK,QAAQ,IAAI,KAAK,IAAI,CAAC,GAAG,CAAC,QAAQ,IAAI,EAAE,CAAC,KAAK,EAAE;QAClE,KAAK;QACL,GAAG,CAAC,KAAK,CAAC,MAAM,KAAK,SAAS,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,CAAC;KAC5D,CAAC,CAAC;IACH,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC;AAC1C,CAAC"}
@@ -0,0 +1,15 @@
1
+ import type { LogRecord } from './types.js';
2
+ /** The JSON format: one record per line, the schema `LogRecord` describes. */
3
+ export declare function formatJson(record: LogRecord): string;
4
+ /**
5
+ * The pretty format, for a person at a terminal:
6
+ * `HH:MM:SS.mmm LEVEL [subsystem] message key=value …`, an error's
7
+ * frames on the lines after. Colours only when `color` is set (a
8
+ * terminal, and `NO_COLOR` unset). `omit`: fields the message already
9
+ * states (`LogOptions.inMessage`), left out of the line.
10
+ */
11
+ export declare function formatPretty(record: LogRecord, options?: {
12
+ readonly color?: boolean;
13
+ readonly omit?: readonly string[];
14
+ }): string;
15
+ //# sourceMappingURL=format.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../src/format.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAmB,MAAM,YAAY,CAAC;AAE7D,8EAA8E;AAC9E,wBAAgB,UAAU,CAAC,MAAM,EAAE,SAAS,GAAG,MAAM,CAIpD;AAsDD;;;;;;GAMG;AACH,wBAAgB,YAAY,CAC1B,MAAM,EAAE,SAAS,EACjB,OAAO,GAAE;IAAE,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;CAAO,GAC5E,MAAM,CAkBR"}
package/dist/format.js ADDED
@@ -0,0 +1,81 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ // Copyright (C) 2026 Kindgi Inc.
3
+ /** The JSON format: one record per line, the schema `LogRecord` describes. */
4
+ export function formatJson(record) {
5
+ return JSON.stringify(record, (_key, value) => typeof value === 'bigint' ? value.toString() : value);
6
+ }
7
+ const LEVEL_LABEL = {
8
+ error: 'ERROR',
9
+ warn: 'WARN ',
10
+ info: 'INFO ',
11
+ debug: 'DEBUG',
12
+ trace: 'TRACE',
13
+ };
14
+ const COLOR = {
15
+ error: '\u001b[31m',
16
+ warn: '\u001b[33m',
17
+ info: '\u001b[36m',
18
+ debug: '\u001b[90m',
19
+ trace: '\u001b[90m',
20
+ };
21
+ const RESET = '\u001b[0m';
22
+ const DIM = '\u001b[2m';
23
+ const FIXED = new Set([
24
+ 'time',
25
+ 'level',
26
+ 'severity',
27
+ 'subsystem',
28
+ 'message',
29
+ 'err',
30
+ ]);
31
+ function pretty(value) {
32
+ if (typeof value === 'string')
33
+ return /[\s"=]/.test(value) || value === '' ? JSON.stringify(value) : value;
34
+ if (typeof value === 'bigint')
35
+ return value.toString();
36
+ if (value === undefined)
37
+ return 'undefined';
38
+ return JSON.stringify(value);
39
+ }
40
+ function errorLines(err) {
41
+ const head = `${err.name}: ${err.message}${err.code !== undefined ? ` (${err.code})` : ''}`;
42
+ const lines = [head];
43
+ if (err.stack !== undefined) {
44
+ const frames = err.stack.split('\n').filter((l) => /^\s*at /.test(l));
45
+ lines.push(...frames.map((f) => ` ${f.trim()}`));
46
+ }
47
+ if (err.cause !== undefined) {
48
+ lines.push(typeof err.cause === 'string'
49
+ ? ` caused by: ${err.cause}`
50
+ : ` caused by: ${errorLines(err.cause).join('\n ')}`);
51
+ }
52
+ return lines;
53
+ }
54
+ /**
55
+ * The pretty format, for a person at a terminal:
56
+ * `HH:MM:SS.mmm LEVEL [subsystem] message key=value …`, an error's
57
+ * frames on the lines after. Colours only when `color` is set (a
58
+ * terminal, and `NO_COLOR` unset). `omit`: fields the message already
59
+ * states (`LogOptions.inMessage`), left out of the line.
60
+ */
61
+ export function formatPretty(record, options = {}) {
62
+ const color = options.color === true;
63
+ const time = record.time.slice(11, 23);
64
+ const label = LEVEL_LABEL[record.level];
65
+ const omit = options.omit ?? [];
66
+ const fields = Object.entries(record)
67
+ .filter(([key, value]) => !FIXED.has(key) && value !== undefined && !omit.includes(key))
68
+ .map(([key, value]) => `${key}=${pretty(value)}`);
69
+ const head = [
70
+ color ? `${DIM}${time}${RESET}` : time,
71
+ color ? `${COLOR[record.level]}${label}${RESET}` : label,
72
+ `[${record.subsystem}]`,
73
+ record.message,
74
+ ...fields,
75
+ ].join(' ');
76
+ if (record.err === undefined)
77
+ return head;
78
+ const [first, ...rest] = errorLines(record.err);
79
+ return [`${head} err=${pretty(first)}`, ...rest].join('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AAC,IAAI,CAAC,CAAC;AAC9D,CAAC"}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * `@kindgi/log` — Kindgi's structured logger: levels (per subsystem, with
3
+ * dotted inheritance), JSON and pretty formats, redaction, and the W3C
4
+ * trace-context helpers. Zero dependencies. The runtime and `@kindgi/api`
5
+ * (`createApp({ logger })`) write the same records.
6
+ */
7
+ export type { LogFields, LogFormat, LogOptions, LogRecord, Logger, SerializedError, } from './types.js';
8
+ export { LOG_LEVELS, type LogLevel, type ParsedLogLevels, SEVERITY, levelEnabled, levelFor, parseLogLevel, parseLogLevels, } from './levels.js';
9
+ export { type CreateLoggerOptions, createLogger, noopLogger } from './logger.js';
10
+ export { formatJson, formatPretty } from './format.js';
11
+ export { REDACTED, isSecretKey, redactValue, scrubText } from './redact.js';
12
+ export { type TraceContext, childSpan, formatTraceparent, newTraceContext, parseTraceparent, traceFromHeader, } from './trace.js';
13
+ export { type LoggerFromEnv, loggerFromEnv, resolveLogFormat } from './env.js';
14
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA;;;;;GAKG;AAEH,YAAY,EACV,SAAS,EACT,SAAS,EACT,UAAU,EACV,SAAS,EACT,MAAM,EACN,eAAe,GAChB,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,UAAU,EACV,KAAK,QAAQ,EACb,KAAK,eAAe,EACpB,QAAQ,EACR,YAAY,EACZ,QAAQ,EACR,aAAa,EACb,cAAc,GACf,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,KAAK,mBAAmB,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACjF,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAC5E,OAAO,EACL,KAAK,YAAY,EACjB,SAAS,EACT,iBAAiB,EACjB,eAAe,EACf,gBAAgB,EAChB,eAAe,GAChB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,KAAK,aAAa,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,9 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ // Copyright (C) 2026 Kindgi Inc.
3
+ export { LOG_LEVELS, SEVERITY, levelEnabled, levelFor, parseLogLevel, parseLogLevels, } from './levels.js';
4
+ export { createLogger, noopLogger } from './logger.js';
5
+ export { formatJson, formatPretty } from './format.js';
6
+ export { REDACTED, isSecretKey, redactValue, scrubText } from './redact.js';
7
+ export { childSpan, formatTraceparent, newTraceContext, parseTraceparent, traceFromHeader, } from './trace.js';
8
+ export { loggerFromEnv, resolveLogFormat } from './env.js';
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,iCAAiC;AAiBjC,OAAO,EACL,UAAU,EAGV,QAAQ,EACR,YAAY,EACZ,QAAQ,EACR,aAAa,EACb,cAAc,GACf,MAAM,aAAa,CAAC;AACrB,OAAO,EAA4B,YAAY,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACjF,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAC5E,OAAO,EAEL,SAAS,EACT,iBAAiB,EACjB,eAAe,EACf,gBAAgB,EAChB,eAAe,GAChB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAsB,aAAa,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC"}
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Log levels, most severe first. A level says how much attention a line
3
+ * needs: `error` (an operator should look), `warn` (unexpected but
4
+ * handled), `info` (what happened, at the operator's grain), `debug` (the
5
+ * decisions behind it), `trace` (internals, briefly).
6
+ */
7
+ export declare const LOG_LEVELS: readonly ["error", "warn", "info", "debug", "trace"];
8
+ export type LogLevel = (typeof LOG_LEVELS)[number];
9
+ /** Cloud Logging's severity names: Cloud Run and GKE show levels with no agent configuration. */
10
+ export declare const SEVERITY: Readonly<Record<LogLevel, string>>;
11
+ /** Whether a record at `level` is written by a logger at `threshold`. */
12
+ export declare function levelEnabled(level: LogLevel, threshold: LogLevel): boolean;
13
+ /** A level's name, case and spaces aside; `undefined` when it isn't one. */
14
+ export declare function parseLogLevel(raw: string): LogLevel | undefined;
15
+ export type ParsedLogLevels = {
16
+ readonly kind: 'ok';
17
+ readonly levels: Readonly<Record<string, LogLevel>>;
18
+ } | {
19
+ readonly kind: 'err';
20
+ readonly message: string;
21
+ };
22
+ /**
23
+ * Per-subsystem levels, `KINDGI_LOG_LEVELS`'s form: a comma list of
24
+ * `subsystem=level`, such as `kernel=debug,http=warn`. Empty is none. An
25
+ * entry that isn't `name=level`, or names no known level, is an error that
26
+ * quotes it. Whether a subsystem exists is the caller's question.
27
+ */
28
+ export declare function parseLogLevels(raw: string): ParsedLogLevels;
29
+ /**
30
+ * The level for `subsystem`: its own entry, else its nearest dotted
31
+ * parent's (`kernel=debug` covers `kernel.sweeper`), else `fallback`.
32
+ */
33
+ export declare function levelFor(subsystem: string, levels: Readonly<Record<string, LogLevel>>, fallback: LogLevel): LogLevel;
34
+ //# sourceMappingURL=levels.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"levels.d.ts","sourceRoot":"","sources":["../src/levels.ts"],"names":[],"mappings":"AAGA;;;;;GAKG;AACH,eAAO,MAAM,UAAU,sDAAuD,CAAC;AAE/E,MAAM,MAAM,QAAQ,GAAG,CAAC,OAAO,UAAU,CAAC,CAAC,MAAM,CAAC,CAAC;AAUnD,iGAAiG;AACjG,eAAO,MAAM,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,QAAQ,EAAE,MAAM,CAAC,CAMvD,CAAC;AAEF,yEAAyE;AACzE,wBAAgB,YAAY,CAAC,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,GAAG,OAAO,CAE1E;AAED,4EAA4E;AAC5E,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,QAAQ,GAAG,SAAS,CAG/D;AAED,MAAM,MAAM,eAAe,GACvB;IAAE,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAA;CAAE,GAC5E;IAAE,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC;AAEvD;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,eAAe,CAiB3D;AAED;;;GAGG;AACH,wBAAgB,QAAQ,CACtB,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,EAC1C,QAAQ,EAAE,QAAQ,GACjB,QAAQ,CASV"}