@trebired/logger 1.1.3 → 2.1.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.
Files changed (142) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/README.md +152 -3
  3. package/dist/browser/console_transport.d.ts +5 -0
  4. package/dist/browser/console_transport.d.ts.map +1 -0
  5. package/dist/browser/console_transport.js +51 -0
  6. package/dist/browser/console_transport.js.map +1 -0
  7. package/dist/browser/create_log.d.ts +4 -0
  8. package/dist/browser/create_log.d.ts.map +1 -0
  9. package/dist/browser/create_log.js +234 -0
  10. package/dist/browser/create_log.js.map +1 -0
  11. package/dist/browser/index.d.ts +4 -0
  12. package/dist/browser/index.d.ts.map +1 -0
  13. package/dist/browser/index.js +3 -0
  14. package/dist/browser/index.js.map +1 -0
  15. package/dist/browser/react.d.ts +30 -0
  16. package/dist/browser/react.d.ts.map +1 -0
  17. package/dist/browser/react.js +44 -0
  18. package/dist/browser/react.js.map +1 -0
  19. package/dist/core/create_log.d.ts.map +1 -1
  20. package/dist/core/create_log.js +121 -145
  21. package/dist/core/create_log.js.map +1 -1
  22. package/dist/core/shared.d.ts +31 -0
  23. package/dist/core/shared.d.ts.map +1 -0
  24. package/dist/core/shared.js +144 -0
  25. package/dist/core/shared.js.map +1 -0
  26. package/dist/format/console.d.ts +2 -2
  27. package/dist/format/console.d.ts.map +1 -1
  28. package/dist/format/console.js +40 -21
  29. package/dist/format/console.js.map +1 -1
  30. package/dist/format/options.d.ts +4 -0
  31. package/dist/format/options.d.ts.map +1 -0
  32. package/dist/format/options.js +19 -0
  33. package/dist/format/options.js.map +1 -0
  34. package/dist/index.d.ts +4 -1
  35. package/dist/index.d.ts.map +1 -1
  36. package/dist/index.js +3 -0
  37. package/dist/index.js.map +1 -1
  38. package/dist/storage/backend/index.d.ts +6 -0
  39. package/dist/storage/backend/index.d.ts.map +1 -0
  40. package/dist/storage/backend/index.js +19 -0
  41. package/dist/storage/backend/index.js.map +1 -0
  42. package/dist/storage/backend/js.d.ts +4 -0
  43. package/dist/storage/backend/js.d.ts.map +1 -0
  44. package/dist/storage/backend/js.js +179 -0
  45. package/dist/storage/backend/js.js.map +1 -0
  46. package/dist/storage/backend/native.d.ts +6 -0
  47. package/dist/storage/backend/native.d.ts.map +1 -0
  48. package/dist/storage/backend/native.js +89 -0
  49. package/dist/storage/backend/native.js.map +1 -0
  50. package/dist/storage/backend/types.d.ts +57 -0
  51. package/dist/storage/backend/types.d.ts.map +1 -0
  52. package/dist/storage/backend/types.js +2 -0
  53. package/dist/storage/backend/types.js.map +1 -0
  54. package/dist/storage/export.d.ts +5 -0
  55. package/dist/storage/export.d.ts.map +1 -0
  56. package/dist/storage/export.js +124 -0
  57. package/dist/storage/export.js.map +1 -0
  58. package/dist/storage/names.d.ts +6 -2
  59. package/dist/storage/names.d.ts.map +1 -1
  60. package/dist/storage/names.js +66 -31
  61. package/dist/storage/names.js.map +1 -1
  62. package/dist/storage/partitions/delete.d.ts +5 -0
  63. package/dist/storage/partitions/delete.d.ts.map +1 -0
  64. package/dist/storage/partitions/delete.js +121 -0
  65. package/dist/storage/partitions/delete.js.map +1 -0
  66. package/dist/storage/partitions/files.d.ts +12 -0
  67. package/dist/storage/partitions/files.d.ts.map +1 -0
  68. package/dist/storage/partitions/files.js +142 -0
  69. package/dist/storage/partitions/files.js.map +1 -0
  70. package/dist/storage/partitions/internal.d.ts +47 -0
  71. package/dist/storage/partitions/internal.d.ts.map +1 -0
  72. package/dist/storage/partitions/internal.js +35 -0
  73. package/dist/storage/partitions/internal.js.map +1 -0
  74. package/dist/storage/partitions/markers.d.ts +8 -0
  75. package/dist/storage/partitions/markers.d.ts.map +1 -0
  76. package/dist/storage/partitions/markers.js +88 -0
  77. package/dist/storage/partitions/markers.js.map +1 -0
  78. package/dist/storage/partitions/public.d.ts +11 -0
  79. package/dist/storage/partitions/public.d.ts.map +1 -0
  80. package/dist/storage/partitions/public.js +79 -0
  81. package/dist/storage/partitions/public.js.map +1 -0
  82. package/dist/storage/partitions/records.d.ts +9 -0
  83. package/dist/storage/partitions/records.d.ts.map +1 -0
  84. package/dist/storage/partitions/records.js +73 -0
  85. package/dist/storage/partitions/records.js.map +1 -0
  86. package/dist/storage/partitions/transforms.d.ts +6 -0
  87. package/dist/storage/partitions/transforms.d.ts.map +1 -0
  88. package/dist/storage/partitions/transforms.js +59 -0
  89. package/dist/storage/partitions/transforms.js.map +1 -0
  90. package/dist/storage/partitions.d.ts +4 -0
  91. package/dist/storage/partitions.d.ts.map +1 -0
  92. package/dist/storage/partitions.js +4 -0
  93. package/dist/storage/partitions.js.map +1 -0
  94. package/dist/storage/query.d.ts +3 -3
  95. package/dist/storage/query.d.ts.map +1 -1
  96. package/dist/storage/query.js +29 -31
  97. package/dist/storage/query.js.map +1 -1
  98. package/dist/storage/retention.d.ts.map +1 -1
  99. package/dist/storage/retention.js +2 -5
  100. package/dist/storage/retention.js.map +1 -1
  101. package/dist/storage/walk.d.ts.map +1 -1
  102. package/dist/storage/walk.js +3 -20
  103. package/dist/storage/walk.js.map +1 -1
  104. package/dist/storage/write.d.ts +1 -2
  105. package/dist/storage/write.d.ts.map +1 -1
  106. package/dist/storage/write.js +10 -12
  107. package/dist/storage/write.js.map +1 -1
  108. package/dist/stream/index.d.ts +11 -3
  109. package/dist/stream/index.d.ts.map +1 -1
  110. package/dist/stream/index.js +40 -4
  111. package/dist/stream/index.js.map +1 -1
  112. package/dist/types/browser.d.ts +54 -0
  113. package/dist/types/browser.d.ts.map +1 -0
  114. package/dist/types/browser.js +2 -0
  115. package/dist/types/browser.js.map +1 -0
  116. package/dist/types/common.d.ts +73 -0
  117. package/dist/types/common.d.ts.map +1 -0
  118. package/dist/types/common.js +2 -0
  119. package/dist/types/common.js.map +1 -0
  120. package/dist/types/export.d.ts +53 -0
  121. package/dist/types/export.d.ts.map +1 -0
  122. package/dist/types/export.js +2 -0
  123. package/dist/types/export.js.map +1 -0
  124. package/dist/types/index.d.ts +7 -0
  125. package/dist/types/index.d.ts.map +1 -0
  126. package/dist/types/index.js +2 -0
  127. package/dist/types/index.js.map +1 -0
  128. package/dist/types/partitions.d.ts +92 -0
  129. package/dist/types/partitions.d.ts.map +1 -0
  130. package/dist/types/partitions.js +2 -0
  131. package/dist/types/partitions.js.map +1 -0
  132. package/dist/types/query.d.ts +49 -0
  133. package/dist/types/query.d.ts.map +1 -0
  134. package/dist/types/query.js +2 -0
  135. package/dist/types/query.js.map +1 -0
  136. package/dist/types/server.d.ts +79 -0
  137. package/dist/types/server.d.ts.map +1 -0
  138. package/dist/types/server.js +2 -0
  139. package/dist/types/server.js.map +1 -0
  140. package/dist/types.d.ts +1 -168
  141. package/dist/types.d.ts.map +1 -1
  142. package/package.json +32 -2
package/CHANGELOG.md CHANGED
@@ -4,6 +4,30 @@ All notable changes to `@trebired/logger` will be documented here.
4
4
 
5
5
  This project follows semantic versioning once published.
6
6
 
7
+ ## Unreleased
8
+
9
+ ## 2.1.0
10
+
11
+ - Added partition export helpers for single-partition and multi-partition exports with `tar.gz` as the default format and `.zip` as an alternate format.
12
+ - Added export convenience methods on live logger instances that flush pending writes before archiving.
13
+ - Added export archives with a shared `manifest.json` while preserving raw exported log files byte-for-byte under `logs/<partition>/...`.
14
+ - Added a Rust native storage backend for partition scanning and archive creation, plus a JS fallback backend and Bun-safe native fallback behavior.
15
+ - Added platform-specific native binary loading so one `@trebired/logger` package can bundle prebuilt Linux and macOS `.node` files under `native/` and select the right binary at runtime.
16
+ - Reused the new storage scan backend for partition info totals so large partition summaries can share the same native/JS seam as export.
17
+ - Changed error console output to keep pretty log headers while emitting a plain `path:line:column` location line and raw stack frames for better terminal and IDE navigation.
18
+
19
+ ## 2.0.0
20
+
21
+ - 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.
22
+ - Added `@trebired/logger/browser/react` with `LogProvider`, `useLog()`, and `LogErrorBoundary` as a thin React adapter on top of the browser runtime.
23
+ - Added a runtime-neutral log stream context so stream listeners can distinguish `{ runtime: "server", dir }` from `{ runtime: "browser", transports }`.
24
+ - Rebuilt partition handling as a clean-break subsystem with no legacy partition marker or legacy log filename compatibility.
25
+ - Added partition naming helpers for time-prefixed names, arbitrary caller suffixes, full-name sanitization, and temporary partition names.
26
+ - Added live partition lifecycle APIs on logger instances, including `getPartition()`, `setPartition()`, `promotePartition()`, `listPartitions()`, and `getPartitionInfo()`.
27
+ - Added standalone partition management helpers for creating, listing, inspecting, renaming, moving, copying, merging, and deleting partitions.
28
+ - Added `deleteLogs()` for file-bucket deletion by partition, age, day, hour, group, level, and temporary-partition filters.
29
+ - Changed query metadata and partition summaries to use real partition names or `null` for unpartitioned logs.
30
+
7
31
  ## 1.1.3
8
32
 
9
33
  - 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,13 +1,29 @@
1
1
  # @trebired/logger
2
2
 
3
- Structured backend logging for Bun and Node.js applications that want readable console output and durable local logs without running a separate logging stack.
3
+ Local-first JSONL logger with human-browsable group folders, durable writes, retention, redaction, query helpers, and more.
4
4
 
5
- `@trebired/logger` writes JSONL logs into group-based folders, supports optional partitioned storage, custom weighted levels, queued file writes, redaction, rolling files, request-scoped loggers, and local query helpers.
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
 
9
9
  Runtime support: Bun 1+ and Node.js 18+.
10
10
 
11
+ The package can use bundled native binaries for supported Linux and macOS targets to speed up large storage/export workloads. Consumers still install a single package:
12
+
13
+ ```txt
14
+ @trebired/logger
15
+ dist/
16
+ native/
17
+ linux-x64-gnu.node
18
+ linux-x64-musl.node
19
+ linux-arm64-gnu.node
20
+ linux-arm64-musl.node
21
+ darwin-arm64.node
22
+ darwin-x64.node
23
+ ```
24
+
25
+ At runtime the JS wrapper selects the matching `.node` file when one is bundled for the current platform, and falls back to the built-in JS backend otherwise. End users do not need Rust installed.
26
+
11
27
  ```sh
12
28
  npm install @trebired/logger
13
29
  ```
@@ -25,6 +41,64 @@ log.info("app.start", "ready", { port: 3000 });
25
41
  await log.flush();
26
42
  ```
27
43
 
44
+ Browser entrypoints:
45
+
46
+ ```ts
47
+ import { createBrowserLog } from "@trebired/logger/browser";
48
+ import { LogProvider, useLog } from "@trebired/logger/browser/react";
49
+ ```
50
+
51
+ ## Browser Runtime
52
+
53
+ Use `@trebired/logger/browser` when you want the same levels, metadata conventions, grouping rules, and scoped logger behavior in browser code:
54
+
55
+ ```ts
56
+ import { createBrowserLog } from "@trebired/logger/browser";
57
+
58
+ const log = createBrowserLog({
59
+ group: "frontend.app",
60
+ metadata: {
61
+ deploymentId: "deploy-42",
62
+ requestId: "req-abc",
63
+ },
64
+ });
65
+
66
+ log.info("frontend boot");
67
+ await log.flush();
68
+ ```
69
+
70
+ 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.
71
+
72
+ 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.
73
+
74
+ ## React Adapter
75
+
76
+ `@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:
77
+
78
+ ```tsx
79
+ import { createRoot } from "react-dom/client";
80
+ import { createBrowserLog } from "@trebired/logger/browser";
81
+ import { LogProvider, useLog } from "@trebired/logger/browser/react";
82
+
83
+ const log = createBrowserLog({
84
+ group: "frontend.app",
85
+ metadata: { deploymentId: "deploy-42" },
86
+ });
87
+
88
+ function SaveButton() {
89
+ const scopedLog = useLog("ui.save_button");
90
+ return <button onClick={() => scopedLog.info("clicked")}>Save</button>;
91
+ }
92
+
93
+ createRoot(document.getElementById("root")!).render(
94
+ <LogProvider log={log}>
95
+ <SaveButton />
96
+ </LogProvider>,
97
+ );
98
+ ```
99
+
100
+ `LogErrorBoundary` is also available from `@trebired/logger/browser/react` when you want render errors logged with the shared event shape.
101
+
28
102
  ## Why This Logger
29
103
 
30
104
  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 +140,78 @@ If you want an extra top-level separation layer, set `partition` and the logger
66
140
  2026-05-03-13-0000-info.jsonl
67
141
  ```
68
142
 
143
+ Partition names can now be built from a stable time prefix plus any caller-defined suffix:
144
+
145
+ ```ts
146
+ import {
147
+ buildPartitionName,
148
+ buildTemporaryPartitionName,
149
+ createLog,
150
+ } from "@trebired/logger";
151
+
152
+ const staged = buildTemporaryPartitionName({
153
+ timeZone: "UTC",
154
+ suffix: "deployment-unknown",
155
+ });
156
+
157
+ const final = buildPartitionName({
158
+ timeZone: "UTC",
159
+ suffix: "deployment-42",
160
+ });
161
+
162
+ const log = createLog({
163
+ dir: "/var/log/my-app",
164
+ partition: staged,
165
+ temporaryPartition: true,
166
+ });
167
+
168
+ log.info("app.boot", "starting before final ownership is known");
169
+ await log.flush();
170
+
171
+ await log.promotePartition(final);
172
+ ```
173
+
174
+ If you already have a full custom partition string, pass it directly with `partition`, or normalize it first with `sanitizePartitionName()`.
175
+
176
+ ## Partition Lifecycle
177
+
178
+ You can manage partitions either from a live logger or with standalone helpers:
179
+
180
+ ```ts
181
+ import {
182
+ copyPartition,
183
+ createPartition,
184
+ deleteLogs,
185
+ listPartitions,
186
+ renamePartition,
187
+ } from "@trebired/logger";
188
+
189
+ await createPartition("/var/log/my-app", "2026-05-17-12-0000-staged", {
190
+ temporary: true,
191
+ });
192
+
193
+ console.log(await listPartitions("/var/log/my-app"));
194
+
195
+ await renamePartition("/var/log/my-app", {
196
+ from: "2026-05-17-12-0000-staged",
197
+ to: "2026-05-17-12-0000-final",
198
+ });
199
+
200
+ await copyPartition({
201
+ fromDir: "/var/log/my-app",
202
+ from: "2026-05-17-12-0000-final",
203
+ toDir: "/var/log/archive",
204
+ to: "2026-05-17-12-0000-final-copy",
205
+ });
206
+
207
+ await deleteLogs("/var/log/my-app", {
208
+ partition: "2026-05-17-12-0000-final",
209
+ groupKey: "jobs.queue",
210
+ level: "warn",
211
+ olderThanDays: 7,
212
+ });
213
+ ```
214
+
69
215
  ## Core API
70
216
 
71
217
  ```ts
@@ -128,6 +274,7 @@ import { createLog } from "@trebired/logger";
128
274
  const log = createLog({
129
275
  dir: "/var/log/my-app",
130
276
  partition: "blue-2026-05-16",
277
+ temporaryPartition: false,
131
278
  save: true,
132
279
  console: {
133
280
  enabled: true,
@@ -358,6 +505,8 @@ console.log(recent.levels);
358
505
  console.log(recent.metadata.total);
359
506
  ```
360
507
 
508
+ Pass `partition: null` when you want only unpartitioned logs from a mixed directory tree.
509
+
361
510
  If you use partition folders and want a merged read across every partition:
362
511
 
363
512
  ```ts
@@ -402,6 +551,6 @@ bun run typecheck
402
551
  bun run build
403
552
  ```
404
553
 
405
- `bun run demo` starts a small dummy system that keeps logging until interrupted. It exercises grouped and scoped loggers, custom levels, redaction, request middleware, live stream events, local querying, and write stats. It writes throwaway logs under the OS temp directory, such as `/tmp/@trebired-logger/dummy` on Linux and macOS. Microslop Windows is not supported.
554
+ `bun run demo` starts a small dummy system that keeps logging until interrupted. It exercises grouped and scoped loggers, custom levels, redaction, request middleware, live stream events, local querying, and write stats. It writes throwaway logs into the repo under `.demo-logs/dummy`. Microslop Windows is not supported.
406
555
 
407
556
  The npm package exports compiled files from `dist`. Publishing runs `typecheck`, tests, and `build` through `prepublishOnly`.
@@ -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,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC;IAChF,IAAI,KAAK,KAAK,MAAM,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,MAAM,CAAC;IAC3D,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAS,wBAAwB,CAAC,KAAe,EAAE,WAA2B,EAAE,OAAiC,EAAE,QAAgB;IACjI,MAAM,YAAY,GAAG,CAAC,WAAW,CAAC,KAAK,IAAI,KAAK,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC,CAAC;IACtE,IAAI,OAAO,CAAC,KAAK;QAAE,YAAY,CAAC,IAAI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EAAE,QAAQ,CAAC,CAAC;gBACpF,MAAM,IAAI,GAAc,CAAC,IAAI,CAAC,CAAC;gBAE/B,IAAI,cAAc,CAAC,QAAQ,IAAI,KAAK,CAAC,QAAQ,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,MAAM;oBAAE,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;gBAC/G,IAAI,WAAW,CAAC,SAAS,KAAK,IAAI,IAAI,KAAK,CAAC,QAAQ,IAAI,KAAK,CAAC,QAAQ,CAAC,KAAK;oBAAE,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC;gBAEtH,MAAM,CAAC,KAAK,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;YAC7B,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC;AAED,OAAO,EAAE,sBAAsB,EAAE,wBAAwB,EAAE,CAAC"}
@@ -0,0 +1,4 @@
1
+ import type { BrowserLogInstance, BrowserLogOptions } from "../types.js";
2
+ declare function createBrowserLog(options?: BrowserLogOptions): BrowserLogInstance;
3
+ export { createBrowserLog };
4
+ //# sourceMappingURL=create_log.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create_log.d.ts","sourceRoot":"","sources":["../../src/browser/create_log.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAEV,kBAAkB,EAClB,iBAAiB,EAKlB,MAAM,aAAa,CAAC;AA2NrB,iBAAS,gBAAgB,CAAC,OAAO,GAAE,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;AAU/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AAchE,SAAS,qBAAqB,CAAC,KAA2B;IACxD,MAAM,GAAG,GAAG,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;IAC5D,MAAM,IAAI,GAAG,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAC9B,MAAM,OAAO,GAAG,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IACpC,MAAM,QAAQ,GAAG,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IACtC,OAAO;QACL,IAAI,EAAE,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE;QAC/D,OAAO,EAAE,MAAM,CAA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AAC;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,3 @@
1
+ export { createBrowserLog } from "./create_log.js";
2
+ export { createConsoleTransport } from "./console_transport.js";
3
+ //# sourceMappingURL=index.js.map
@@ -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