@comity/logger 0.0.0-stage → 0.10.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/LICENSE +21 -0
- package/README.md +65 -2
- package/dist/contracts/log-record.d.ts +55 -0
- package/dist/contracts/log-record.js +2 -0
- package/dist/contracts/logger.d.ts +62 -0
- package/dist/contracts/logger.js +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/package.json +56 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Filippo Bovo and contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,66 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @comity/logger
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Technology-independent logging contracts for Comity.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Purpose
|
|
8
|
+
|
|
9
|
+
Defines the contracts used to emit structured log records without binding
|
|
10
|
+
Comity to a logging technology. Technology Adapters implement these contracts;
|
|
11
|
+
the core package carries no logging implementation, no transport, and no
|
|
12
|
+
configuration.
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
## Scope
|
|
17
|
+
|
|
18
|
+
This package:
|
|
19
|
+
|
|
20
|
+
- ✅ defines a closed five-level severity vocabulary
|
|
21
|
+
- ✅ defines a generic, application-defined structured field bag
|
|
22
|
+
- ✅ defines a structured log record with a distinct `unknown` error channel
|
|
23
|
+
- ✅ defines child logger binding semantics and their collision precedence
|
|
24
|
+
|
|
25
|
+
This package does NOT:
|
|
26
|
+
|
|
27
|
+
- ❌ implements a logging technology, transport, or sink
|
|
28
|
+
- ❌ generates timestamps
|
|
29
|
+
- ❌ provides a no-op logger, a fallback logger, or any runtime helper
|
|
30
|
+
- ❌ defines enrichment, metrics, tracing, or OpenTelemetry integration
|
|
31
|
+
- ❌ supplies a dependency-injection token or a setup entry point
|
|
32
|
+
- ❌ guarantees delivery, durability, ordering, or persistence
|
|
33
|
+
|
|
34
|
+
---
|
|
35
|
+
|
|
36
|
+
## Public API
|
|
37
|
+
|
|
38
|
+
- `LogLevel` — the closed five-level severity union
|
|
39
|
+
- `LogFields` — the generic structured field bag
|
|
40
|
+
- `LogRecord` — a single structured log record
|
|
41
|
+
- `Logger` — the technology-independent logging contract
|
|
42
|
+
|
|
43
|
+
No exhaustive reference; see docs for constraints.
|
|
44
|
+
|
|
45
|
+
---
|
|
46
|
+
|
|
47
|
+
## Documentation
|
|
48
|
+
|
|
49
|
+
- docs/overview.md
|
|
50
|
+
- docs/conventions.md
|
|
51
|
+
|
|
52
|
+
---
|
|
53
|
+
|
|
54
|
+
## Dependencies
|
|
55
|
+
|
|
56
|
+
None.
|
|
57
|
+
|
|
58
|
+
The package declares no runtime dependency, no peer dependency, and no
|
|
59
|
+
dependency on any other Comity package. Its two development dependencies are
|
|
60
|
+
`typescript` and `@types/node`.
|
|
61
|
+
|
|
62
|
+
---
|
|
63
|
+
|
|
64
|
+
## Status
|
|
65
|
+
|
|
66
|
+
Stable
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Log severity levels.
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* A closed set of exactly five levels: `trace`, `debug`, `info`, `warn` and
|
|
6
|
+
* `error`. The contract defines no numeric severity, no ordering and no
|
|
7
|
+
* threshold — a level is an opaque tag. An implementation MAY define an
|
|
8
|
+
* ordering for its own filtering, but that ordering is not part of the
|
|
9
|
+
* contract, and an implementation MUST NOT synthesize a level outside this
|
|
10
|
+
* set.
|
|
11
|
+
*/
|
|
12
|
+
export type LogLevel = "trace" | "debug" | "info" | "warn" | "error";
|
|
13
|
+
/**
|
|
14
|
+
* Structured fields carried by a log record.
|
|
15
|
+
*
|
|
16
|
+
* @remarks
|
|
17
|
+
* A generic, closed-key-free bag of opaque values. The contract prescribes
|
|
18
|
+
* no field names — not `tenantId`, `requestId`, `correlationId`, `traceId` or
|
|
19
|
+
* `spanId`, and not any other — requires no nesting depth, value type or
|
|
20
|
+
* serializability, and an implementation MUST NOT interpret the values.
|
|
21
|
+
* Trace and span identifiers are ordinary application-supplied fields.
|
|
22
|
+
*/
|
|
23
|
+
export type LogFields = Readonly<Record<string, unknown>>;
|
|
24
|
+
/**
|
|
25
|
+
* A single structured log record.
|
|
26
|
+
*
|
|
27
|
+
* @remarks
|
|
28
|
+
* The `error` channel is a distinct property, separate from `fields`, typed
|
|
29
|
+
* `unknown`. The error value is not merged into `fields`: a field named
|
|
30
|
+
* `error` and the error channel remain distinguishable. The contract
|
|
31
|
+
* imposes no serialization rule on the error value or on any field value.
|
|
32
|
+
*/
|
|
33
|
+
export interface LogRecord {
|
|
34
|
+
/** Severity of the record. */
|
|
35
|
+
readonly level: LogLevel;
|
|
36
|
+
/** Human-readable message. */
|
|
37
|
+
readonly message: string;
|
|
38
|
+
/**
|
|
39
|
+
* Optional structured fields.
|
|
40
|
+
*
|
|
41
|
+
* @remarks
|
|
42
|
+
* Absence is expressed by omitting the key. With
|
|
43
|
+
* `exactOptionalPropertyTypes` enabled, passing `undefined` explicitly is
|
|
44
|
+
* not permitted.
|
|
45
|
+
*/
|
|
46
|
+
readonly fields?: LogFields;
|
|
47
|
+
/**
|
|
48
|
+
* Optional error value.
|
|
49
|
+
*
|
|
50
|
+
* @remarks
|
|
51
|
+
* Absence is expressed by omitting the key. The value is typed `unknown`,
|
|
52
|
+
* so every value is accepted, including `undefined`.
|
|
53
|
+
*/
|
|
54
|
+
readonly error?: unknown;
|
|
55
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { LogFields, LogRecord } from "./log-record.js";
|
|
2
|
+
/**
|
|
3
|
+
* Technology-independent logging contract.
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* The contract is **best-effort**. It makes no guarantee of persistence,
|
|
7
|
+
* delivery, durability, ordering across processes, or observability of
|
|
8
|
+
* internal failures.
|
|
9
|
+
*
|
|
10
|
+
* **No-throw posture.** No logging method and no `child()` call may throw.
|
|
11
|
+
* No method may reject or return a failure. A failure inside an
|
|
12
|
+
* implementation — a serialization failure, a transport failure, or an
|
|
13
|
+
* internal defect — MUST be contained within the implementation and MUST NOT
|
|
14
|
+
* surface to the caller, nor alter application control flow.
|
|
15
|
+
*
|
|
16
|
+
* **Child semantics.** `child(bindings)` creates a logger carrying the
|
|
17
|
+
* supplied bindings. Child creation MUST NOT mutate the parent. Nested
|
|
18
|
+
* children inherit their ancestors' bindings. Collision precedence is
|
|
19
|
+
* `parent bindings < child bindings < record fields`. Bindings do not apply
|
|
20
|
+
* retroactively. There is no ambient context mechanism: `child` returns a
|
|
21
|
+
* value and installs no process-, thread- or async-scoped state.
|
|
22
|
+
*
|
|
23
|
+
* **Child after an internal failure.** `child()` has no failure channel of
|
|
24
|
+
* its own, so it has exactly one permitted outcome: it returns a `Logger`.
|
|
25
|
+
* When an internal failure prevents normal child creation, the
|
|
26
|
+
* implementation MUST still return a `Logger` satisfying this same
|
|
27
|
+
* contract, so that the caller can continue to use it without a null check,
|
|
28
|
+
* a type assertion or a try/catch. The fallback MUST NOT mutate the parent
|
|
29
|
+
* and MUST NOT introduce ambient or global state. The degradation applies
|
|
30
|
+
* only to the failure path: when normal child creation succeeds, the child
|
|
31
|
+
* semantics above hold in full and a degraded logger MUST NOT be
|
|
32
|
+
* substituted for a successful one. After a failure the contract CANNOT
|
|
33
|
+
* guarantee that the requested bindings are carried — an implementation MAY
|
|
34
|
+
* apply them if it can do so safely and MAY omit them if it cannot, but it
|
|
35
|
+
* MUST NOT represent the returned logger as carrying bindings it does not
|
|
36
|
+
* carry, and it MUST NOT signal the degradation by throwing or by returning
|
|
37
|
+
* a failure. The degradation is observable only in the records the returned
|
|
38
|
+
* logger emits. The fallback is implementation-specific and internal: it
|
|
39
|
+
* MUST NOT introduce a public fallback class, an additional contract symbol,
|
|
40
|
+
* or any other public API element.
|
|
41
|
+
*/
|
|
42
|
+
export interface Logger {
|
|
43
|
+
/** Emit a structured log record. */
|
|
44
|
+
log(record: LogRecord): void;
|
|
45
|
+
/** Emit a trace-level message. */
|
|
46
|
+
trace(message: string, fields?: LogFields): void;
|
|
47
|
+
/** Emit a debug-level message. */
|
|
48
|
+
debug(message: string, fields?: LogFields): void;
|
|
49
|
+
/** Emit an info-level message. */
|
|
50
|
+
info(message: string, fields?: LogFields): void;
|
|
51
|
+
/** Emit a warn-level message. */
|
|
52
|
+
warn(message: string, fields?: LogFields): void;
|
|
53
|
+
/** Emit an error-level message. */
|
|
54
|
+
error(message: string, fields?: LogFields): void;
|
|
55
|
+
/**
|
|
56
|
+
* Create a child logger carrying the supplied bindings.
|
|
57
|
+
*
|
|
58
|
+
* @remarks
|
|
59
|
+
* Never throws, and always returns a usable `Logger`.
|
|
60
|
+
*/
|
|
61
|
+
child(bindings: LogFields): Logger;
|
|
62
|
+
}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,59 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@comity/logger",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.10.0",
|
|
4
|
+
"description": "Technology-independent logging contract for Comity framework.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"private": false,
|
|
7
|
+
"author": "Filippo Bovo <hello@filippobovo.com>",
|
|
8
|
+
"license": "MIT",
|
|
9
|
+
"comity": {
|
|
10
|
+
"layer": "core"
|
|
11
|
+
},
|
|
12
|
+
"homepage": "https://github.com/comityjs/framework#readme",
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "https://github.com/comityjs/framework.git"
|
|
16
|
+
},
|
|
17
|
+
"bugs": {
|
|
18
|
+
"url": "https://github.com/comityjs/framework/issues"
|
|
19
|
+
},
|
|
20
|
+
"engines": {
|
|
21
|
+
"node": ">=24.0.0"
|
|
22
|
+
},
|
|
23
|
+
"keywords": [
|
|
24
|
+
"comity",
|
|
25
|
+
"comityjs",
|
|
26
|
+
"logger",
|
|
27
|
+
"logging",
|
|
28
|
+
"typescript"
|
|
29
|
+
],
|
|
30
|
+
"files": [
|
|
31
|
+
"dist",
|
|
32
|
+
"!dist/**/*.map"
|
|
33
|
+
],
|
|
34
|
+
"main": "./dist/index.js",
|
|
35
|
+
"types": "./dist/index.d.ts",
|
|
36
|
+
"exports": {
|
|
37
|
+
".": {
|
|
38
|
+
"types": "./dist/index.d.ts",
|
|
39
|
+
"default": "./dist/index.js"
|
|
40
|
+
},
|
|
41
|
+
"./package.json": "./package.json"
|
|
42
|
+
},
|
|
43
|
+
"publishConfig": {
|
|
44
|
+
"registry": "https://registry.npmjs.org",
|
|
45
|
+
"access": "public"
|
|
46
|
+
},
|
|
47
|
+
"sideEffects": false,
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"@types/node": "^24.19.2",
|
|
50
|
+
"typescript": "^5.9.3"
|
|
51
|
+
},
|
|
52
|
+
"scripts": {
|
|
53
|
+
"build": "node ../../scripts/build.mjs",
|
|
54
|
+
"dev": "node ../../scripts/build.mjs --watch",
|
|
55
|
+
"test": "vitest run --coverage",
|
|
56
|
+
"type-check": "tsc -p tsconfig.json --noEmit",
|
|
57
|
+
"lint": "eslint --ext .ts src"
|
|
58
|
+
}
|
|
6
59
|
}
|