@trebired/logger 1.1.3 → 2.0.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/CHANGELOG.md +12 -0
- package/README.md +135 -2
- package/dist/browser/console_transport.d.ts +5 -0
- package/dist/browser/console_transport.d.ts.map +1 -0
- package/dist/browser/console_transport.js +51 -0
- package/dist/browser/console_transport.js.map +1 -0
- package/dist/browser/create_log.d.ts +4 -0
- package/dist/browser/create_log.d.ts.map +1 -0
- package/dist/browser/create_log.js +234 -0
- package/dist/browser/create_log.js.map +1 -0
- package/dist/browser/index.d.ts +4 -0
- package/dist/browser/index.d.ts.map +1 -0
- package/dist/browser/index.js +3 -0
- package/dist/browser/index.js.map +1 -0
- package/dist/browser/react.d.ts +30 -0
- package/dist/browser/react.d.ts.map +1 -0
- package/dist/browser/react.js +44 -0
- package/dist/browser/react.js.map +1 -0
- package/dist/core/create_log.d.ts.map +1 -1
- package/dist/core/create_log.js +105 -145
- package/dist/core/create_log.js.map +1 -1
- package/dist/core/shared.d.ts +31 -0
- package/dist/core/shared.d.ts.map +1 -0
- package/dist/core/shared.js +144 -0
- package/dist/core/shared.js.map +1 -0
- package/dist/format/console.d.ts +2 -2
- package/dist/format/console.d.ts.map +1 -1
- package/dist/format/console.js +2 -17
- package/dist/format/console.js.map +1 -1
- package/dist/format/options.d.ts +4 -0
- package/dist/format/options.d.ts.map +1 -0
- package/dist/format/options.js +19 -0
- package/dist/format/options.js.map +1 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/storage/names.d.ts +6 -2
- package/dist/storage/names.d.ts.map +1 -1
- package/dist/storage/names.js +66 -31
- package/dist/storage/names.js.map +1 -1
- package/dist/storage/partitions.d.ts +30 -0
- package/dist/storage/partitions.d.ts.map +1 -0
- package/dist/storage/partitions.js +564 -0
- package/dist/storage/partitions.js.map +1 -0
- package/dist/storage/query.d.ts +3 -3
- package/dist/storage/query.d.ts.map +1 -1
- package/dist/storage/query.js +29 -31
- package/dist/storage/query.js.map +1 -1
- package/dist/storage/retention.d.ts.map +1 -1
- package/dist/storage/retention.js +2 -5
- package/dist/storage/retention.js.map +1 -1
- package/dist/storage/walk.d.ts.map +1 -1
- package/dist/storage/walk.js +3 -20
- package/dist/storage/walk.js.map +1 -1
- package/dist/storage/write.d.ts +1 -2
- package/dist/storage/write.d.ts.map +1 -1
- package/dist/storage/write.js +10 -12
- package/dist/storage/write.js.map +1 -1
- package/dist/stream/index.d.ts +11 -3
- package/dist/stream/index.d.ts.map +1 -1
- package/dist/stream/index.js +40 -4
- package/dist/stream/index.js.map +1 -1
- package/dist/types.d.ts +162 -4
- package/dist/types.d.ts.map +1 -1
- package/package.json +24 -2
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,18 @@ All notable changes to `@trebired/logger` will be documented here.
|
|
|
4
4
|
|
|
5
5
|
This project follows semantic versioning once published.
|
|
6
6
|
|
|
7
|
+
## 2.0.0
|
|
8
|
+
|
|
9
|
+
- Added `@trebired/logger/browser` for framework-neutral browser logging with the same levels, metadata conventions, grouping rules, and scoped logger behavior as the server logger.
|
|
10
|
+
- Added `@trebired/logger/browser/react` with `LogProvider`, `useLog()`, and `LogErrorBoundary` as a thin React adapter on top of the browser runtime.
|
|
11
|
+
- Added a runtime-neutral log stream context so stream listeners can distinguish `{ runtime: "server", dir }` from `{ runtime: "browser", transports }`.
|
|
12
|
+
- Rebuilt partition handling as a clean-break subsystem with no legacy partition marker or legacy log filename compatibility.
|
|
13
|
+
- Added partition naming helpers for time-prefixed names, arbitrary caller suffixes, full-name sanitization, and temporary partition names.
|
|
14
|
+
- Added live partition lifecycle APIs on logger instances, including `getPartition()`, `setPartition()`, `promotePartition()`, `listPartitions()`, and `getPartitionInfo()`.
|
|
15
|
+
- Added standalone partition management helpers for creating, listing, inspecting, renaming, moving, copying, merging, and deleting partitions.
|
|
16
|
+
- Added `deleteLogs()` for file-bucket deletion by partition, age, day, hour, group, level, and temporary-partition filters.
|
|
17
|
+
- Changed query metadata and partition summaries to use real partition names or `null` for unpartitioned logs.
|
|
18
|
+
|
|
7
19
|
## 1.1.3
|
|
8
20
|
|
|
9
21
|
- Added optional `partition` storage folders so one logger dir can keep separate deployments, sessions, environments, or other caller-defined log trees.
|
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# @trebired/logger
|
|
2
2
|
|
|
3
|
-
Structured
|
|
3
|
+
Structured logging for server and browser applications that want one event model, readable console output, and durable local logs without running a separate logging stack.
|
|
4
4
|
|
|
5
|
-
`@trebired/logger` writes JSONL logs into group-based folders, supports optional partitioned storage,
|
|
5
|
+
`@trebired/logger` writes JSONL logs into group-based folders on the server, supports optional partitioned storage, and now ships a framework-neutral browser runtime with an optional React adapter on top.
|
|
6
6
|
|
|
7
7
|
## Install
|
|
8
8
|
|
|
@@ -25,6 +25,64 @@ log.info("app.start", "ready", { port: 3000 });
|
|
|
25
25
|
await log.flush();
|
|
26
26
|
```
|
|
27
27
|
|
|
28
|
+
Browser entrypoints:
|
|
29
|
+
|
|
30
|
+
```ts
|
|
31
|
+
import { createBrowserLog } from "@trebired/logger/browser";
|
|
32
|
+
import { LogProvider, useLog } from "@trebired/logger/browser/react";
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Browser Runtime
|
|
36
|
+
|
|
37
|
+
Use `@trebired/logger/browser` when you want the same levels, metadata conventions, grouping rules, and scoped logger behavior in browser code:
|
|
38
|
+
|
|
39
|
+
```ts
|
|
40
|
+
import { createBrowserLog } from "@trebired/logger/browser";
|
|
41
|
+
|
|
42
|
+
const log = createBrowserLog({
|
|
43
|
+
group: "frontend.app",
|
|
44
|
+
metadata: {
|
|
45
|
+
deploymentId: "deploy-42",
|
|
46
|
+
requestId: "req-abc",
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
log.info("frontend boot");
|
|
51
|
+
await log.flush();
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
The first browser release ships with console delivery built in. It also supports custom browser transports with in-memory batching so you can add fetch, beacon, websocket, or other delivery later without changing the logger API.
|
|
55
|
+
|
|
56
|
+
There is no built-in SSR bootstrap helper in this release. If you want browser correlation data such as `requestId`, `sessionId`, or `deploymentId`, pass it explicitly through `metadata` or per-log metadata.
|
|
57
|
+
|
|
58
|
+
## React Adapter
|
|
59
|
+
|
|
60
|
+
`@trebired/logger/browser/react` is intentionally thin. It does not create a logger for you. It only helps wire an existing browser logger into React context:
|
|
61
|
+
|
|
62
|
+
```tsx
|
|
63
|
+
import { createRoot } from "react-dom/client";
|
|
64
|
+
import { createBrowserLog } from "@trebired/logger/browser";
|
|
65
|
+
import { LogProvider, useLog } from "@trebired/logger/browser/react";
|
|
66
|
+
|
|
67
|
+
const log = createBrowserLog({
|
|
68
|
+
group: "frontend.app",
|
|
69
|
+
metadata: { deploymentId: "deploy-42" },
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
function SaveButton() {
|
|
73
|
+
const scopedLog = useLog("ui.save_button");
|
|
74
|
+
return <button onClick={() => scopedLog.info("clicked")}>Save</button>;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
createRoot(document.getElementById("root")!).render(
|
|
78
|
+
<LogProvider log={log}>
|
|
79
|
+
<SaveButton />
|
|
80
|
+
</LogProvider>,
|
|
81
|
+
);
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
`LogErrorBoundary` is also available from `@trebired/logger/browser/react` when you want render errors logged with the shared event shape.
|
|
85
|
+
|
|
28
86
|
## Why This Logger
|
|
29
87
|
|
|
30
88
|
Most loggers either write to stdout and expect an external collector, or provide a very broad transport system. This package is intentionally opinionated around a simpler operational workflow:
|
|
@@ -66,6 +124,78 @@ If you want an extra top-level separation layer, set `partition` and the logger
|
|
|
66
124
|
2026-05-03-13-0000-info.jsonl
|
|
67
125
|
```
|
|
68
126
|
|
|
127
|
+
Partition names can now be built from a stable time prefix plus any caller-defined suffix:
|
|
128
|
+
|
|
129
|
+
```ts
|
|
130
|
+
import {
|
|
131
|
+
buildPartitionName,
|
|
132
|
+
buildTemporaryPartitionName,
|
|
133
|
+
createLog,
|
|
134
|
+
} from "@trebired/logger";
|
|
135
|
+
|
|
136
|
+
const staged = buildTemporaryPartitionName({
|
|
137
|
+
timeZone: "UTC",
|
|
138
|
+
suffix: "deployment-unknown",
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
const final = buildPartitionName({
|
|
142
|
+
timeZone: "UTC",
|
|
143
|
+
suffix: "deployment-42",
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
const log = createLog({
|
|
147
|
+
dir: "/var/log/my-app",
|
|
148
|
+
partition: staged,
|
|
149
|
+
temporaryPartition: true,
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
log.info("app.boot", "starting before final ownership is known");
|
|
153
|
+
await log.flush();
|
|
154
|
+
|
|
155
|
+
await log.promotePartition(final);
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
If you already have a full custom partition string, pass it directly with `partition`, or normalize it first with `sanitizePartitionName()`.
|
|
159
|
+
|
|
160
|
+
## Partition Lifecycle
|
|
161
|
+
|
|
162
|
+
You can manage partitions either from a live logger or with standalone helpers:
|
|
163
|
+
|
|
164
|
+
```ts
|
|
165
|
+
import {
|
|
166
|
+
copyPartition,
|
|
167
|
+
createPartition,
|
|
168
|
+
deleteLogs,
|
|
169
|
+
listPartitions,
|
|
170
|
+
renamePartition,
|
|
171
|
+
} from "@trebired/logger";
|
|
172
|
+
|
|
173
|
+
await createPartition("/var/log/my-app", "2026-05-17-12-0000-staged", {
|
|
174
|
+
temporary: true,
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
console.log(await listPartitions("/var/log/my-app"));
|
|
178
|
+
|
|
179
|
+
await renamePartition("/var/log/my-app", {
|
|
180
|
+
from: "2026-05-17-12-0000-staged",
|
|
181
|
+
to: "2026-05-17-12-0000-final",
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
await copyPartition({
|
|
185
|
+
fromDir: "/var/log/my-app",
|
|
186
|
+
from: "2026-05-17-12-0000-final",
|
|
187
|
+
toDir: "/var/log/archive",
|
|
188
|
+
to: "2026-05-17-12-0000-final-copy",
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
await deleteLogs("/var/log/my-app", {
|
|
192
|
+
partition: "2026-05-17-12-0000-final",
|
|
193
|
+
groupKey: "jobs.queue",
|
|
194
|
+
level: "warn",
|
|
195
|
+
olderThanDays: 7,
|
|
196
|
+
});
|
|
197
|
+
```
|
|
198
|
+
|
|
69
199
|
## Core API
|
|
70
200
|
|
|
71
201
|
```ts
|
|
@@ -128,6 +258,7 @@ import { createLog } from "@trebired/logger";
|
|
|
128
258
|
const log = createLog({
|
|
129
259
|
dir: "/var/log/my-app",
|
|
130
260
|
partition: "blue-2026-05-16",
|
|
261
|
+
temporaryPartition: false,
|
|
131
262
|
save: true,
|
|
132
263
|
console: {
|
|
133
264
|
enabled: true,
|
|
@@ -358,6 +489,8 @@ console.log(recent.levels);
|
|
|
358
489
|
console.log(recent.metadata.total);
|
|
359
490
|
```
|
|
360
491
|
|
|
492
|
+
Pass `partition: null` when you want only unpartitioned logs from a mixed directory tree.
|
|
493
|
+
|
|
361
494
|
If you use partition folders and want a merged read across every partition:
|
|
362
495
|
|
|
363
496
|
```ts
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { BrowserConsoleTransportOptions, BrowserTransport, LogEntry, LogLevelConfig, NormalizedConsoleOptions } from "../types.js";
|
|
2
|
+
declare function formatBrowserConsoleLine(entry: LogEntry, levelConfig: LogLevelConfig, options: NormalizedConsoleOptions, timeZone: string): string;
|
|
3
|
+
declare function createConsoleTransport(options?: BrowserConsoleTransportOptions): BrowserTransport;
|
|
4
|
+
export { createConsoleTransport, formatBrowserConsoleLine };
|
|
5
|
+
//# sourceMappingURL=console_transport.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"console_transport.d.ts","sourceRoot":"","sources":["../../src/browser/console_transport.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,8BAA8B,EAC9B,gBAAgB,EAChB,QAAQ,EACR,cAAc,EACd,wBAAwB,EACzB,MAAM,aAAa,CAAC;AASrB,iBAAS,wBAAwB,CAAC,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,cAAc,EAAE,OAAO,EAAE,wBAAwB,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAW3I;AAED,iBAAS,sBAAsB,CAAC,OAAO,GAAE,8BAAmC,GAAG,gBAAgB,CA0B9F;AAED,OAAO,EAAE,sBAAsB,EAAE,wBAAwB,EAAE,CAAC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { formatDisplayTimestamp } from "../utils/datetime.js";
|
|
2
|
+
import { normalizeConsoleOptions } from "../format/options.js";
|
|
3
|
+
import { normalizeLevels } from "../levels/index.js";
|
|
4
|
+
function consoleMethodName(level, levelConfig) {
|
|
5
|
+
if (level === "debug")
|
|
6
|
+
return "debug";
|
|
7
|
+
if (levelConfig.stream === "stderr")
|
|
8
|
+
return level === "warn" ? "warn" : "error";
|
|
9
|
+
if (level === "info" || level === "success")
|
|
10
|
+
return "info";
|
|
11
|
+
return "log";
|
|
12
|
+
}
|
|
13
|
+
function formatBrowserConsoleLine(entry, levelConfig, options, timeZone) {
|
|
14
|
+
const bracketParts = [levelConfig.label || entry.level.toUpperCase()];
|
|
15
|
+
if (options.group)
|
|
16
|
+
bracketParts.push(entry.group);
|
|
17
|
+
let line = `[${bracketParts.join(", ")}] ${entry.message}`;
|
|
18
|
+
if (options.timestamp) {
|
|
19
|
+
line = `|${formatDisplayTimestamp(entry.recorded_at, options.locale, timeZone)}| ${line}`;
|
|
20
|
+
}
|
|
21
|
+
return line;
|
|
22
|
+
}
|
|
23
|
+
function createConsoleTransport(options = {}) {
|
|
24
|
+
const consoleOptions = normalizeConsoleOptions(options.console);
|
|
25
|
+
const timeZone = options.timeZone || "UTC";
|
|
26
|
+
const levels = normalizeLevels(options.levels);
|
|
27
|
+
return {
|
|
28
|
+
name: "console",
|
|
29
|
+
write(entries) {
|
|
30
|
+
if (!consoleOptions.enabled)
|
|
31
|
+
return;
|
|
32
|
+
const target = globalThis.console;
|
|
33
|
+
if (!target)
|
|
34
|
+
return;
|
|
35
|
+
for (const entry of entries) {
|
|
36
|
+
const levelConfig = levels[entry.level] || levels.info;
|
|
37
|
+
const methodName = consoleMethodName(entry.level, levelConfig);
|
|
38
|
+
const method = typeof target[methodName] === "function" ? target[methodName] : target.log;
|
|
39
|
+
const line = formatBrowserConsoleLine(entry, levelConfig, consoleOptions, timeZone);
|
|
40
|
+
const args = [line];
|
|
41
|
+
if (consoleOptions.metadata && entry.metadata && Object.keys(entry.metadata).length)
|
|
42
|
+
args.push(entry.metadata);
|
|
43
|
+
if (levelConfig.showStack === true && entry.metadata && entry.metadata.stack)
|
|
44
|
+
args.push(String(entry.metadata.stack));
|
|
45
|
+
method.apply(target, args);
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
export { createConsoleTransport, formatBrowserConsoleLine };
|
|
51
|
+
//# sourceMappingURL=console_transport.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"console_transport.js","sourceRoot":"","sources":["../../src/browser/console_transport.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAC9D,OAAO,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AAC/D,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AASrD,SAAS,iBAAiB,CAAC,KAAa,EAAE,WAA2B;IACnE,IAAI,KAAK,KAAK,OAAO;QAAE,OAAO,OAAO,CAAC;IACtC,IAAI,WAAW,CAAC,MAAM,KAAK,QAAQ;QAAE,OAAO,KAAK,KAAK,MAAM,CAAC,C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E,iBAAsB,GAAG,kBAAkB,CAkC7E;AAED,OAAO,EAAE,gBAAgB,EAAE,CAAC"}
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
import { createCommonLogger } from "../core/shared.js";
|
|
2
|
+
import { normalizeLevels } from "../levels/index.js";
|
|
3
|
+
import { logStream } from "../stream/index.js";
|
|
4
|
+
import { normalizeTimeZone } from "../utils/datetime.js";
|
|
5
|
+
import { asObject, toString } from "../utils/values.js";
|
|
6
|
+
import { createConsoleTransport } from "./console_transport.js";
|
|
7
|
+
function normalizeBatchOptions(input) {
|
|
8
|
+
const cfg = input && typeof input === "object" ? input : {};
|
|
9
|
+
const size = Number(cfg.size);
|
|
10
|
+
const delayMs = Number(cfg.delayMs);
|
|
11
|
+
const maxQueue = Number(cfg.maxQueue);
|
|
12
|
+
return {
|
|
13
|
+
size: Number.isFinite(size) && size > 0 ? Math.floor(size) : 20,
|
|
14
|
+
delayMs: Number.isFinite(delayMs) && delayMs >= 0 ? Math.floor(delayMs) : 1000,
|
|
15
|
+
maxQueue: Number.isFinite(maxQueue) && maxQueue > 0 ? Math.floor(maxQueue) : 1000,
|
|
16
|
+
overflow: cfg.overflow === "drop-oldest" || cfg.overflow === "throw" ? cfg.overflow : "drop-newest",
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
function resolveTransports(options, levels, timeZone) {
|
|
20
|
+
const transportInputs = Array.isArray(options.transports) ? options.transports : ["console"];
|
|
21
|
+
const resolved = [];
|
|
22
|
+
for (const input of transportInputs) {
|
|
23
|
+
if (input === "console") {
|
|
24
|
+
if (options.console === false)
|
|
25
|
+
continue;
|
|
26
|
+
resolved.push({
|
|
27
|
+
transport: createConsoleTransport({
|
|
28
|
+
console: options.console,
|
|
29
|
+
timeZone,
|
|
30
|
+
levels,
|
|
31
|
+
}),
|
|
32
|
+
immediate: true,
|
|
33
|
+
});
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
if (!input || typeof input !== "object")
|
|
37
|
+
continue;
|
|
38
|
+
if (typeof input.available === "function" && input.available() !== true)
|
|
39
|
+
continue;
|
|
40
|
+
resolved.push({ transport: input, immediate: false });
|
|
41
|
+
}
|
|
42
|
+
return resolved;
|
|
43
|
+
}
|
|
44
|
+
class BrowserTransportManager {
|
|
45
|
+
constructor(transports, batchOptions) {
|
|
46
|
+
this.queue = [];
|
|
47
|
+
this.timer = null;
|
|
48
|
+
this.flushing = null;
|
|
49
|
+
this.closed = false;
|
|
50
|
+
this.immediateTransports = transports.filter((item) => item.immediate).map((item) => item.transport);
|
|
51
|
+
this.batchedTransports = transports.filter((item) => !item.immediate).map((item) => item.transport);
|
|
52
|
+
this.batchOptions = normalizeBatchOptions(batchOptions);
|
|
53
|
+
this.stats = {
|
|
54
|
+
queued: 0,
|
|
55
|
+
written: 0,
|
|
56
|
+
dropped: 0,
|
|
57
|
+
failed: 0,
|
|
58
|
+
queueLength: 0,
|
|
59
|
+
closed: false,
|
|
60
|
+
transports: transports.map((item) => item.transport.name),
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
getContext() {
|
|
64
|
+
return {
|
|
65
|
+
runtime: "browser",
|
|
66
|
+
transports: this.stats.transports.slice(),
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
write(entry) {
|
|
70
|
+
if (this.closed) {
|
|
71
|
+
this.stats.dropped += 1;
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
let wroteImmediate = false;
|
|
75
|
+
for (const transport of this.immediateTransports) {
|
|
76
|
+
try {
|
|
77
|
+
const result = transport.write([entry], this.getContext());
|
|
78
|
+
if (result && typeof result.catch === "function") {
|
|
79
|
+
void result.catch(() => {
|
|
80
|
+
this.stats.failed += 1;
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
wroteImmediate = true;
|
|
84
|
+
}
|
|
85
|
+
catch {
|
|
86
|
+
this.stats.failed += 1;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
if (wroteImmediate)
|
|
90
|
+
this.stats.written += 1;
|
|
91
|
+
if (!this.batchedTransports.length)
|
|
92
|
+
return;
|
|
93
|
+
if (this.queue.length >= this.batchOptions.maxQueue) {
|
|
94
|
+
if (this.batchOptions.overflow === "throw")
|
|
95
|
+
throw new Error("browser-log-queue-full");
|
|
96
|
+
if (this.batchOptions.overflow === "drop-oldest")
|
|
97
|
+
this.queue.shift();
|
|
98
|
+
this.stats.dropped += 1;
|
|
99
|
+
if (this.batchOptions.overflow === "drop-newest")
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
this.queue.push(entry);
|
|
103
|
+
this.stats.queued += 1;
|
|
104
|
+
this.stats.queueLength = this.queue.length;
|
|
105
|
+
if (this.queue.length >= this.batchOptions.size) {
|
|
106
|
+
void this.flushQueue();
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
this.ensureTimer();
|
|
110
|
+
}
|
|
111
|
+
async flush() {
|
|
112
|
+
this.clearTimer();
|
|
113
|
+
await this.flushQueue();
|
|
114
|
+
for (const transport of [...this.immediateTransports, ...this.batchedTransports]) {
|
|
115
|
+
if (typeof transport.flush !== "function")
|
|
116
|
+
continue;
|
|
117
|
+
try {
|
|
118
|
+
await transport.flush();
|
|
119
|
+
}
|
|
120
|
+
catch {
|
|
121
|
+
this.stats.failed += Math.max(1, this.queue.length);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
async close() {
|
|
126
|
+
if (this.closed)
|
|
127
|
+
return;
|
|
128
|
+
this.closed = true;
|
|
129
|
+
this.stats.closed = true;
|
|
130
|
+
this.clearTimer();
|
|
131
|
+
await this.flush();
|
|
132
|
+
for (const transport of [...this.immediateTransports, ...this.batchedTransports]) {
|
|
133
|
+
if (typeof transport.close !== "function")
|
|
134
|
+
continue;
|
|
135
|
+
try {
|
|
136
|
+
await transport.close();
|
|
137
|
+
}
|
|
138
|
+
catch {
|
|
139
|
+
this.stats.failed += 1;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
getStats() {
|
|
144
|
+
return {
|
|
145
|
+
...this.stats,
|
|
146
|
+
queueLength: this.queue.length,
|
|
147
|
+
closed: this.closed,
|
|
148
|
+
transports: this.stats.transports.slice(),
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
ensureTimer() {
|
|
152
|
+
if (this.timer || this.closed || this.batchOptions.delayMs <= 0)
|
|
153
|
+
return;
|
|
154
|
+
this.timer = setTimeout(() => {
|
|
155
|
+
this.timer = null;
|
|
156
|
+
void this.flushQueue();
|
|
157
|
+
}, this.batchOptions.delayMs);
|
|
158
|
+
}
|
|
159
|
+
clearTimer() {
|
|
160
|
+
if (!this.timer)
|
|
161
|
+
return;
|
|
162
|
+
clearTimeout(this.timer);
|
|
163
|
+
this.timer = null;
|
|
164
|
+
}
|
|
165
|
+
async flushQueue() {
|
|
166
|
+
if (!this.batchedTransports.length || this.queue.length === 0)
|
|
167
|
+
return;
|
|
168
|
+
if (this.flushing) {
|
|
169
|
+
await this.flushing;
|
|
170
|
+
if (this.queue.length > 0)
|
|
171
|
+
await this.flushQueue();
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
this.flushing = (async () => {
|
|
175
|
+
while (this.queue.length > 0) {
|
|
176
|
+
const entries = this.queue.splice(0, this.queue.length);
|
|
177
|
+
this.stats.queueLength = this.queue.length;
|
|
178
|
+
let failed = false;
|
|
179
|
+
for (const transport of this.batchedTransports) {
|
|
180
|
+
try {
|
|
181
|
+
await transport.write(entries, this.getContext());
|
|
182
|
+
}
|
|
183
|
+
catch {
|
|
184
|
+
failed = true;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
if (failed)
|
|
188
|
+
this.stats.failed += entries.length;
|
|
189
|
+
else if (this.immediateTransports.length === 0)
|
|
190
|
+
this.stats.written += entries.length;
|
|
191
|
+
}
|
|
192
|
+
})().finally(() => {
|
|
193
|
+
this.flushing = null;
|
|
194
|
+
this.stats.queueLength = this.queue.length;
|
|
195
|
+
});
|
|
196
|
+
await this.flushing;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
function createBrowserLog(options = {}) {
|
|
200
|
+
const cfg = options && typeof options === "object" ? options : {};
|
|
201
|
+
const levels = normalizeLevels(cfg.levels);
|
|
202
|
+
const timeZone = normalizeTimeZone(cfg.timeZone);
|
|
203
|
+
const transports = resolveTransports(cfg, levels, timeZone);
|
|
204
|
+
const manager = new BrowserTransportManager(transports, cfg.batch);
|
|
205
|
+
const { api } = createCommonLogger({
|
|
206
|
+
levels,
|
|
207
|
+
minLevel: cfg.minLevel,
|
|
208
|
+
defaultSource: toString(cfg.source) || "browser",
|
|
209
|
+
defaultGroup: toString(cfg.group) || undefined,
|
|
210
|
+
defaultMetadata: asObject(cfg.metadata),
|
|
211
|
+
serializers: cfg.serializers,
|
|
212
|
+
redact: cfg.redact,
|
|
213
|
+
sample: cfg.sample,
|
|
214
|
+
writeEntry(entry) {
|
|
215
|
+
manager.write(entry);
|
|
216
|
+
try {
|
|
217
|
+
logStream.emit("log", entry, manager.getContext());
|
|
218
|
+
}
|
|
219
|
+
catch { }
|
|
220
|
+
},
|
|
221
|
+
flush() {
|
|
222
|
+
return manager.flush();
|
|
223
|
+
},
|
|
224
|
+
close() {
|
|
225
|
+
return manager.close();
|
|
226
|
+
},
|
|
227
|
+
getStats() {
|
|
228
|
+
return manager.getStats();
|
|
229
|
+
},
|
|
230
|
+
});
|
|
231
|
+
return api;
|
|
232
|
+
}
|
|
233
|
+
export { createBrowserLog };
|
|
234
|
+
//# sourceMappingURL=create_log.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create_log.js","sourceRoot":"","sources":["../../src/browser/create_log.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;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BAAkB,CAAkB;QAClD,MAAM;QACN,QAAQ,EAAE,GAAG,CAAC,QAAQ;QACtB,aAAa,EAAE,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,SAAS;QAChD,YAAY,EAAE,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,SAAS;QAC9C,eAAe,EAAE,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC;QACvC,WAAW,EAAE,GAAG,CAAC,WAAW;QAC5B,MAAM,EAAE,GAAG,CAAC,MAAM;QAClB,MAAM,EAAE,GAAG,CAAC,MAAM;QAClB,UAAU,CAAC,KAAK;YACd,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;YACrB,IAAI,CAAC;gBACH,SAAS,CAAC,IAAI,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,CAAC,UAAU,EAAE,CAAC,CAAC;YACrD,CAAC;YAAC,MAAM,CAAC,CAAA,CAAC;QACZ,CAAC;QACD,KAAK;YACH,OAAO,OAAO,CAAC,KAAK,EAAE,CAAC;QACzB,CAAC;QACD,KAAK;YACH,OAAO,OAAO,CAAC,KAAK,EAAE,CAAC;QACzB,CAAC;QACD,QAAQ;YACN,OAAO,OAAO,CAAC,QAAQ,EAAE,CAAC;QAC5B,CAAC;KACF,CAAC,CAAC;IAEH,OAAO,GAAyB,CAAC;AACnC,CAAC;AAED,OAAO,EAAE,gBAAgB,EAAE,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { createBrowserLog } from "./create_log.js";
|
|
2
|
+
export { createConsoleTransport } from "./console_transport.js";
|
|
3
|
+
export type { BrowserBatchOptions, BrowserConsoleTransportOptions, BrowserLogInstance, BrowserLogOptions, BrowserLogStats, BrowserTransport, BrowserTransportContext, } from "../types.js";
|
|
4
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/browser/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AAEhE,YAAY,EACV,mBAAmB,EACnB,8BAA8B,EAC9B,kBAAkB,EAClB,iBAAiB,EACjB,eAAe,EACf,gBAAgB,EAChB,uBAAuB,GACxB,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/browser/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import React, { Component } from "react";
|
|
2
|
+
import type { BrowserLogInstance } from "../types.js";
|
|
3
|
+
type LogProviderProps = {
|
|
4
|
+
log: BrowserLogInstance;
|
|
5
|
+
children?: React.ReactNode;
|
|
6
|
+
};
|
|
7
|
+
type LogErrorBoundaryProps = {
|
|
8
|
+
log?: BrowserLogInstance;
|
|
9
|
+
group?: string;
|
|
10
|
+
metadata?: Record<string, unknown>;
|
|
11
|
+
fallback?: React.ReactNode | ((error: Error) => React.ReactNode);
|
|
12
|
+
children?: React.ReactNode;
|
|
13
|
+
};
|
|
14
|
+
type LogErrorBoundaryState = {
|
|
15
|
+
error: Error | null;
|
|
16
|
+
};
|
|
17
|
+
declare const LogContext: React.Context<BrowserLogInstance>;
|
|
18
|
+
declare function LogProvider({ log, children }: LogProviderProps): React.FunctionComponentElement<React.ProviderProps<BrowserLogInstance>>;
|
|
19
|
+
declare function useLog(groupName?: string): BrowserLogInstance | Record<string, any>;
|
|
20
|
+
declare class LogErrorBoundary extends Component<LogErrorBoundaryProps, LogErrorBoundaryState> {
|
|
21
|
+
static contextType: React.Context<BrowserLogInstance>;
|
|
22
|
+
context: React.ContextType<typeof LogContext>;
|
|
23
|
+
state: LogErrorBoundaryState;
|
|
24
|
+
static getDerivedStateFromError(error: Error): LogErrorBoundaryState;
|
|
25
|
+
componentDidCatch(error: Error, info: React.ErrorInfo): void;
|
|
26
|
+
render(): React.ReactNode;
|
|
27
|
+
}
|
|
28
|
+
export { LogErrorBoundary, LogProvider, useLog };
|
|
29
|
+
export type { LogErrorBoundaryProps, LogProviderProps };
|
|
30
|
+
//# sourceMappingURL=react.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"react.d.ts","sourceRoot":"","sources":["../../src/browser/react.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,SAAS,EAA6B,MAAM,OAAO,CAAC;AAEpE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAEtD,KAAK,gBAAgB,GAAG;IACtB,GAAG,EAAE,kBAAkB,CAAC;IACxB,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CAC5B,CAAC;AAEF,KAAK,qBAAqB,GAAG;IAC3B,GAAG,CAAC,EAAE,kBAAkB,CAAC;IACzB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACnC,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,GAAG,CAAC,CAAC,KAAK,EAAE,KAAK,KAAK,KAAK,CAAC,SAAS,CAAC,CAAC;IACjE,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CAC5B,CAAC;AAEF,KAAK,qBAAqB,GAAG;IAC3B,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;CACrB,CAAC;AAEF,QAAA,MAAM,UAAU,mCAAiD,CAAC;AAElE,iBAAS,WAAW,CAAC,EAAE,GAAG,EAAE,QAAQ,EAAE,EAAE,gBAAgB,2EAEvD;AAED,iBAAS,MAAM,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,kBAAkB,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAI5E;AAED,cAAM,gBAAiB,SAAQ,SAAS,CAAC,qBAAqB,EAAE,qBAAqB,CAAC;IACpF,MAAM,CAAC,WAAW,oCAAc;IACxB,OAAO,EAAE,KAAK,CAAC,WAAW,CAAC,OAAO,UAAU,CAAC,CAAC;IAEtD,KAAK,EAAE,qBAAqB,CAE1B;IAEF,MAAM,CAAC,wBAAwB,CAAC,KAAK,EAAE,KAAK,GAAG,qBAAqB;IAMpE,iBAAiB,CAAC,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,CAAC,SAAS,GAAG,IAAI;IAe5D,MAAM,IAAI,KAAK,CAAC,SAAS;CAK1B;AAED,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,EAAE,CAAC;AACjD,YAAY,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import React, { Component, createContext, useContext } from "react";
|
|
2
|
+
const LogContext = createContext(null);
|
|
3
|
+
function LogProvider({ log, children }) {
|
|
4
|
+
return React.createElement(LogContext.Provider, { value: log }, children);
|
|
5
|
+
}
|
|
6
|
+
function useLog(groupName) {
|
|
7
|
+
const log = useContext(LogContext);
|
|
8
|
+
if (!log)
|
|
9
|
+
throw new Error("missing-log-provider");
|
|
10
|
+
return groupName ? log.group(groupName) : log;
|
|
11
|
+
}
|
|
12
|
+
class LogErrorBoundary extends Component {
|
|
13
|
+
constructor() {
|
|
14
|
+
super(...arguments);
|
|
15
|
+
this.state = {
|
|
16
|
+
error: null,
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
static getDerivedStateFromError(error) {
|
|
20
|
+
return {
|
|
21
|
+
error,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
componentDidCatch(error, info) {
|
|
25
|
+
const logger = this.props.log || this.context;
|
|
26
|
+
if (!logger)
|
|
27
|
+
return;
|
|
28
|
+
logger.logError(error, {
|
|
29
|
+
...(this.props.metadata || {}),
|
|
30
|
+
group: this.props.group || "react.error_boundary",
|
|
31
|
+
componentStack: info.componentStack,
|
|
32
|
+
}, "react");
|
|
33
|
+
}
|
|
34
|
+
render() {
|
|
35
|
+
if (!this.state.error)
|
|
36
|
+
return this.props.children;
|
|
37
|
+
if (typeof this.props.fallback === "function")
|
|
38
|
+
return this.props.fallback(this.state.error);
|
|
39
|
+
return this.props.fallback ?? null;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
LogErrorBoundary.contextType = LogContext;
|
|
43
|
+
export { LogErrorBoundary, LogProvider, useLog };
|
|
44
|
+
//# sourceMappingURL=react.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"react.js","sourceRoot":"","sources":["../../src/browser/react.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,SAAS,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAqBpE,MAAM,UAAU,GAAG,aAAa,CAA4B,IAAI,CAAC,CAAC;AAElE,SAAS,WAAW,CAAC,EAAE,GAAG,EAAE,QAAQ,EAAoB;IACtD,OAAO,KAAK,CAAC,aAAa,CAAC,UAAU,CAAC,QAAQ,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE,QAAQ,CAAC,CAAC;AAC5E,CAAC;AAED,SAAS,MAAM,CAAC,SAAkB;IAChC,MAAM,GAAG,GAAG,UAAU,CAAC,UAAU,CAAC,CAAC;IACnC,IAAI,CAAC,GAAG;QAAE,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC;IAClD,OAAO,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;AAChD,CAAC;AAED,MAAM,gBAAiB,SAAQ,SAAuD;IAAtF;;QAIE,UAAK,GAA0B;YAC7B,KAAK,EAAE,IAAI;SACZ,CAAC;IA4BJ,CAAC;IA1BC,MAAM,CAAC,wBAAwB,CAAC,KAAY;QAC1C,OAAO;YACL,KAAK;SACN,CAAC;IACJ,CAAC;IAED,iBAAiB,CAAC,KAAY,EAAE,IAAqB;QACnD,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,IAAI,IAAI,CAAC,OAAO,CAAC;QAC9C,IAAI,CAAC,MAAM;YAAE,OAAO;QAEpB,MAAM,CAAC,QAAQ,CACb,KAAK,EACL;YACE,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,IAAI,EAAE,CAAC;YAC9B,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,IAAI,sBAAsB;YACjD,cAAc,EAAE,IAAI,CAAC,cAAc;SACpC,EACD,OAAO,CACR,CAAC;IACJ,CAAC;IAED,MAAM;QACJ,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK;YAAE,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC;QAClD,IAAI,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,KAAK,UAAU;YAAE,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QAC5F,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,IAAI,IAAI,CAAC;IACrC,CAAC;;AAhCM,4BAAW,GAAG,UAAU,AAAb,CAAc;AAmClC,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,EAAE,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create_log.d.ts","sourceRoot":"","sources":["../../src/core/create_log.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"create_log.d.ts","sourceRoot":"","sources":["../../src/core/create_log.ts"],"names":[],"mappings":"AAmBA,OAAO,KAAK,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAYjE,iBAAS,SAAS,CAAC,OAAO,GAAE,gBAAqB,GAAG,WAAW,CAkJ9D;AAED,OAAO,EAAE,SAAS,EAAE,CAAC"}
|