@effectstream/log 0.100.13 → 0.100.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/README.md +83 -0
- package/package.json +2 -2
- package/test/examples.test.ts +52 -0
package/README.md
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
# @effectstream/log
|
|
2
|
+
|
|
3
|
+
OpenTelemetry-instrumented structured logging for EffectStream. Wraps
|
|
4
|
+
`tslog` and the OpenTelemetry SDK behind a single `log` object that emits
|
|
5
|
+
both pretty console output (`log.local`) and OTLP traces/logs to your
|
|
6
|
+
collector (`log.remote`).
|
|
7
|
+
|
|
8
|
+
## Install
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
bun add @effectstream/log
|
|
12
|
+
# or
|
|
13
|
+
npm install @effectstream/log
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Standalone usage
|
|
17
|
+
|
|
18
|
+
Any Node service that wants colored terminal logs plus OTLP export with one
|
|
19
|
+
dependency.
|
|
20
|
+
|
|
21
|
+
```typescript
|
|
22
|
+
import {
|
|
23
|
+
ComponentNames,
|
|
24
|
+
defaultOtelSetup,
|
|
25
|
+
log,
|
|
26
|
+
SeverityNumber,
|
|
27
|
+
} from "@effectstream/log";
|
|
28
|
+
|
|
29
|
+
// Initialize OpenTelemetry once at startup (optional — defaults work too).
|
|
30
|
+
defaultOtelSetup({ serviceName: "my-app" });
|
|
31
|
+
|
|
32
|
+
// Local-only: pretty console output, no OTLP.
|
|
33
|
+
log.local(
|
|
34
|
+
"my-app", // component name (any string)
|
|
35
|
+
"startup", // namespace
|
|
36
|
+
SeverityNumber.INFO,
|
|
37
|
+
(l) => l("started on port", 3000),
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
// Remote: console + OpenTelemetry log record + trace correlation.
|
|
41
|
+
log.remote(
|
|
42
|
+
"my-app",
|
|
43
|
+
"auth",
|
|
44
|
+
SeverityNumber.INFO,
|
|
45
|
+
(l) => l("user logged in", { userId: "u_123" }),
|
|
46
|
+
);
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
The deferred `(l) => l(...)` form means message construction is skipped
|
|
50
|
+
entirely when the level is filtered out — handy when log arguments are
|
|
51
|
+
expensive to format (`JSON.stringify` of a big object).
|
|
52
|
+
|
|
53
|
+
Point the SDK at any OTLP-compatible collector (Grafana Alloy, Tempo,
|
|
54
|
+
Honeycomb, …) via the standard `OTEL_EXPORTER_OTLP_ENDPOINT` env var.
|
|
55
|
+
|
|
56
|
+
## Inside EffectStream
|
|
57
|
+
|
|
58
|
+
Every package in the framework — sync, runtime, batcher, sm — logs through
|
|
59
|
+
this module so the whole node emits one consistent trace tree. The
|
|
60
|
+
`ComponentNames` constants tag log records by component, which is what
|
|
61
|
+
powers the orchestrator's per-component log views.
|
|
62
|
+
|
|
63
|
+
## Key exports
|
|
64
|
+
|
|
65
|
+
- `log.local(component, namespace, level, deferred)` — console-only logging. `level` is `SeverityNumber`; `deferred = (l) => l(...args)` is called only if the level passes the filter.
|
|
66
|
+
- `log.localForce(...)` — bypasses level filtering.
|
|
67
|
+
- `log.remote(...)` — console + OpenTelemetry log record. Same signature as `local`.
|
|
68
|
+
- `log.remoteForce(...)` — `remote` without level filtering.
|
|
69
|
+
- `log.formatMessage(...)` — the formatter used internally; useful for custom transports.
|
|
70
|
+
- `defaultOtelSetup(opts)` — one-call OpenTelemetry SDK setup with sensible defaults.
|
|
71
|
+
- `attachTransport(transport)` — register a custom tslog transport (e.g. ship logs to a file).
|
|
72
|
+
- `SeverityNumber` — re-export of OpenTelemetry severity levels.
|
|
73
|
+
- `ComponentNames` — string-enum constants used to tag logs by component.
|
|
74
|
+
- `Namespace` — `string | string[]` for log namespacing.
|
|
75
|
+
|
|
76
|
+
## Examples
|
|
77
|
+
|
|
78
|
+
Runnable: [`test/examples.test.ts`](./test/examples.test.ts).
|
|
79
|
+
|
|
80
|
+
## Links
|
|
81
|
+
|
|
82
|
+
- Docs: https://effectstream.github.io/docs/packages/sdk/log
|
|
83
|
+
- Source: https://github.com/PaimaStudios/paima-engine/tree/main/packages/effectstream-sdk/log
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@effectstream/log",
|
|
3
|
-
"version": "0.100.
|
|
3
|
+
"version": "0.100.15",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"homepage": "https://effectstream.github.io/docs/",
|
|
6
6
|
"repository": {
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
},
|
|
14
14
|
"exports": "./src/mod.ts",
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@effectstream/utils": "0.100.
|
|
16
|
+
"@effectstream/utils": "0.100.15",
|
|
17
17
|
"@opentelemetry/api": "^1.9.0",
|
|
18
18
|
"@opentelemetry/api-logs": "0.56.0",
|
|
19
19
|
"@opentelemetry/exporter-logs-otlp-http": "0.56.0",
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// Examples for the README.
|
|
2
|
+
|
|
3
|
+
import { test, expect } from "bun:test";
|
|
4
|
+
import { ComponentNames, log, SeverityNumber } from "../src/mod.ts";
|
|
5
|
+
|
|
6
|
+
test("README: log.local accepts a deferred message function", () => {
|
|
7
|
+
let called = 0;
|
|
8
|
+
log.local(
|
|
9
|
+
"my-app",
|
|
10
|
+
"startup",
|
|
11
|
+
SeverityNumber.INFO,
|
|
12
|
+
(l) => {
|
|
13
|
+
called++;
|
|
14
|
+
l("started on port", 3000);
|
|
15
|
+
},
|
|
16
|
+
);
|
|
17
|
+
// The deferred is invoked synchronously at the appropriate level.
|
|
18
|
+
expect(called).toBe(1);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
test("README: log.remote accepts the same signature as log.local", () => {
|
|
22
|
+
let called = 0;
|
|
23
|
+
log.remote(
|
|
24
|
+
"my-app",
|
|
25
|
+
"auth",
|
|
26
|
+
SeverityNumber.INFO,
|
|
27
|
+
(l) => {
|
|
28
|
+
called++;
|
|
29
|
+
l("user logged in", { userId: "u_123" });
|
|
30
|
+
},
|
|
31
|
+
);
|
|
32
|
+
expect(called).toBe(1);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
test("README: log.localForce bypasses level filtering", () => {
|
|
36
|
+
let called = 0;
|
|
37
|
+
log.localForce(
|
|
38
|
+
"my-app",
|
|
39
|
+
"audit",
|
|
40
|
+
SeverityNumber.DEBUG,
|
|
41
|
+
(l) => {
|
|
42
|
+
called++;
|
|
43
|
+
l("low-severity message that would normally be filtered");
|
|
44
|
+
},
|
|
45
|
+
);
|
|
46
|
+
expect(called).toBe(1);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
test("README: ComponentNames are usable as component tags", () => {
|
|
50
|
+
expect(typeof ComponentNames.EFFECTSTREAM_SYNC).toBe("string");
|
|
51
|
+
expect(typeof ComponentNames.EFFECTSTREAM_RUNTIME).toBe("string");
|
|
52
|
+
});
|