@murky-web/simplelog 2.0.1 → 3.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 (55) hide show
  1. package/README.md +151 -16
  2. package/dist/browser_console.js +91 -0
  3. package/dist/browser_console.js.map +1 -0
  4. package/dist/{deno_logger.d.ts → browser_logger.d.ts} +1 -3
  5. package/dist/browser_logger.d.ts.map +1 -0
  6. package/dist/browser_logger.js +17 -0
  7. package/dist/browser_logger.js.map +1 -0
  8. package/dist/bun_logger.d.ts +0 -2
  9. package/dist/bun_logger.d.ts.map +1 -1
  10. package/dist/bun_logger.js +1 -2
  11. package/dist/bun_logger.js.map +1 -1
  12. package/dist/console_defaults.js +45 -0
  13. package/dist/console_defaults.js.map +1 -0
  14. package/dist/console_text.d.ts +25 -0
  15. package/dist/console_text.d.ts.map +1 -0
  16. package/dist/console_text.js +168 -0
  17. package/dist/console_text.js.map +1 -0
  18. package/dist/console_timestamp.d.ts +4 -0
  19. package/dist/console_timestamp.d.ts.map +1 -0
  20. package/dist/console_timestamp.js +22 -0
  21. package/dist/console_timestamp.js.map +1 -0
  22. package/dist/hono_middleware.d.ts +14 -4
  23. package/dist/hono_middleware.d.ts.map +1 -1
  24. package/dist/hono_middleware.js +45 -20
  25. package/dist/hono_middleware.js.map +1 -1
  26. package/dist/log_file.d.ts +9 -0
  27. package/dist/log_file.d.ts.map +1 -0
  28. package/dist/log_file.js +52 -0
  29. package/dist/log_file.js.map +1 -0
  30. package/dist/logger.d.ts +0 -2
  31. package/dist/logger.d.ts.map +1 -1
  32. package/dist/logger.js +1 -2
  33. package/dist/logger.js.map +1 -1
  34. package/dist/logger_factory.d.ts +45 -11
  35. package/dist/logger_factory.d.ts.map +1 -1
  36. package/dist/logger_factory.js +38 -217
  37. package/dist/logger_factory.js.map +1 -1
  38. package/dist/node_runtime.js +17 -6
  39. package/dist/node_runtime.js.map +1 -1
  40. package/dist/otel.d.ts +0 -2
  41. package/dist/otel.d.ts.map +1 -1
  42. package/dist/otel.js +2 -3
  43. package/dist/serialize_value.d.ts +44 -0
  44. package/dist/serialize_value.d.ts.map +1 -0
  45. package/dist/serialize_value.js +313 -0
  46. package/dist/serialize_value.js.map +1 -0
  47. package/dist/web_logger.d.ts +0 -2
  48. package/dist/web_logger.d.ts.map +1 -1
  49. package/dist/web_logger.js +3 -3
  50. package/dist/web_logger.js.map +1 -1
  51. package/oxlint/prefer-runtime-entry.mjs +1 -1
  52. package/package.json +19 -13
  53. package/dist/deno_logger.d.ts.map +0 -1
  54. package/dist/deno_logger.js +0 -39
  55. package/dist/deno_logger.js.map +0 -1
package/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # SimpleLog
2
2
 
3
- `SimpleLog` is a lightweight and flexible logging utility for Node.js, Bun,
4
- Deno, and fetch-style edge runtimes. It provides various log levels, performance
3
+ `SimpleLog` is a lightweight and flexible logging utility for Node.js, Bun and
4
+ fetch-style edge runtimes. It provides various log levels, performance
5
5
  benchmarking, and the ability to log messages to both the console and a file.
6
6
 
7
7
  ## Features
@@ -43,12 +43,6 @@ Bun:
43
43
  import { Logger } from "@murky-web/simplelog/bun";
44
44
  ```
45
45
 
46
- Deno:
47
-
48
- ```typescript
49
- import { Logger } from "@murky-web/simplelog/deno";
50
- ```
51
-
52
46
  Web and edge runtimes:
53
47
 
54
48
  ```typescript
@@ -91,21 +85,133 @@ childLogger.info("This is a message from the child logger");
91
85
  - `logFilePath`: Path to the log file.
92
86
  - `logLevelThreshold`: Minimum log level for logging.
93
87
  - `valueColorMode`: `"level" | "syntax" | "off"` for console value coloring.
88
+ - `timestampFormat`: `"iso" | "time"` for the console timestamp.
94
89
  - `includeOpenTelemetryContext`: Adds active `trace_id` and `span_id` to each
95
90
  log line when an OpenTelemetry span is active.
96
91
 
97
92
  `valueColorMode` modes:
98
93
 
99
- - `level`: current default, all console pieces use the log-level color
94
+ - `level`: all console pieces use the log-level color
100
95
  - `syntax`: extra values use type-based colors like strings, numbers, booleans,
101
96
  nullish values, symbols, and objects
102
97
  - `off`: console output stays plain
103
98
 
99
+ `timestampFormat` modes:
100
+
101
+ - `iso`: the full UTC timestamp, `2026-11-19T16:59:23.745Z`
102
+ - `time`: the local time of day, `16:59:23.745`
103
+
104
+ ### Defaults for colors and timestamps
105
+
106
+ Without the option, the Node and Bun entries pick both from the environment when
107
+ a logger is created. Child loggers inherit the parent's values.
108
+
109
+ Colors (`valueColorMode`), `NO_COLOR` as https://no-color.org defines it plus
110
+ Node's `FORCE_COLOR` values:
111
+
112
+ 1. `NO_COLOR` set and not empty: `"off"`.
113
+ 2. `FORCE_COLOR` set: `"level"`, even when empty, except `FORCE_COLOR=0` or
114
+ `false`, which means `"off"`.
115
+ 3. Otherwise `"level"` when stdout is a terminal, `"off"` when it is a pipe or a
116
+ file (CI, systemd, Docker, a process manager).
117
+
118
+ The check looks at stdout only. Stack traces of `error()` and `assert()` go to
119
+ stderr with the same colors, so `app 2>errors.log` in a terminal writes ANSI
120
+ codes into `errors.log`; set `NO_COLOR=1` there.
121
+
122
+ Timestamp (`timestampFormat`):
123
+
124
+ 1. `SIMPLELOG_TIMESTAMP=time` or `SIMPLELOG_TIMESTAMP=iso`.
125
+ 2. Otherwise `"time"` when stdout is a terminal, `"iso"` when it is not.
126
+
127
+ Set `SIMPLELOG_TIMESTAMP=time` for output that goes through a pipe but is read
128
+ by people, for example a process manager's terminal UI.
129
+
130
+ An explicit option always wins over the environment. Log files always get the
131
+ ISO timestamp and never colors, whatever the console shows. The `web` entry has
132
+ no terminal to ask: it keeps `"level"` and `"iso"`.
133
+
134
+ ### In the browser
135
+
136
+ Bundlers that build for the browser resolve `@murky-web/simplelog/web` through
137
+ its `browser` export condition to a smaller logger with the same API. It prints
138
+ differently:
139
+
140
+ - Arguments go to the console as they are, so DevTools shows objects you can
141
+ expand. Only the `Error` rules under "How arguments are printed" apply: an
142
+ `Error` argument is shown as a copy with `name`, `message`, `stack`, `cause`,
143
+ `code` and `errors`, and a `cause` that is no Error as `"[Object]"`. An Error
144
+ nested inside another object is shown in full.
145
+ - Only the header (timestamp, level, logger name, message) is colored, with CSS
146
+ through `%c`. `"syntax"` colors it like `"level"`; DevTools colors the values
147
+ itself. `"off"` leaves it plain.
148
+ - `writeToFile` and `logFilePath` do nothing.
149
+
150
+ Server runtimes keep the text logger: the `workerd`, `worker`, `edge-light`,
151
+ `deno`, `bun` and `node` conditions come before `browser`, and Vite's SSR build
152
+ resolves `node`. A bundler that builds server code with only the `browser`
153
+ condition gets the browser logger: `Error` arguments are still cut down, but
154
+ an Error inside another object, `Map` or `Set` keeps all its properties, and
155
+ nothing is truncated. Vite does that with `ssr.target: "webworker"` unless
156
+ `ssr.resolve.conditions` names one of the server conditions, for example
157
+ `["workerd", "worker"]`.
158
+
104
159
  `includeOpenTelemetryContext` is intentionally opt-in. When enabled, `simplelog`
105
160
  reads the current active span from `@opentelemetry/api` and appends `trace_id`
106
161
  and `span_id` to console and file output. It does not install an OpenTelemetry
107
162
  SDK or exporter for you.
108
163
 
164
+ ## Output Format
165
+
166
+ ### File lines
167
+
168
+ A log file entry is the console line without colors: ISO timestamp, level,
169
+ logger name, message, then every additional argument separated by a space.
170
+ Objects are written as compact, single-line JSON (the console keeps the indented
171
+ form), so one entry is one line.
172
+
173
+ Control characters, the Unicode line and paragraph separators (U+2028, U+2029),
174
+ the bidirectional controls (U+200E, U+200F, U+061C, U+202A to U+202E, U+2066 to
175
+ U+2069) and the byte order mark (U+FEFF) in the message, the logger name and the
176
+ arguments are written as `\n`, `\r` or `\uXXXX`. A value cannot start a line of
177
+ its own or disguise one. Tab and backslash are left alone (escaping backslashes
178
+ would mangle Windows paths), so the file is readable text, not an encoding you
179
+ can reverse unambiguously.
180
+
181
+ A stack trace is written after its entry as continuation lines, each starting
182
+ with a tab. Every entry starts with a timestamp, never with a tab.
183
+
184
+ ### How arguments are printed
185
+
186
+ - An `Error` prints only `name`, `message`, `stack`, `cause`, `code` when it is
187
+ a string or a number, and, for an `AggregateError`, `errors`. All other
188
+ properties are left out on purpose: HTTP client errors (axios, got) carry the
189
+ request, its headers and its body there.
190
+ - Inside an Error, `cause` and the elements of `errors` print in full only when
191
+ they are Errors themselves (same rules, recursively). Primitives print as they
192
+ are. Any other object prints as `"[Object]"`, because a `cause` is often an
193
+ HTTP response or request with credentials in it.
194
+ - `Map` prints as `{ "Map": [[key, value]] }`, `Set` as `{ "Set": [value] }`,
195
+ `BigInt` as `"123n"`, a function as `"[Function name]"`, `String`, `Number`
196
+ and `Boolean` objects as their primitive value.
197
+ - Typed arrays, `DataView` and `ArrayBuffer` print as a label with their byte
198
+ length, for example `"[Uint8Array 5000000 bytes]"`. Their contents are not
199
+ printed.
200
+ - Cycles print as `"[Circular]"`, nesting deeper than 8 levels as
201
+ `"[MaxDepth]"`.
202
+ - A call prints at most 1000 values per argument, and 50 keys per object and 50
203
+ items per array, `Map` or `Set`. What is left out is shown as `"[Truncated]"`
204
+ (an object gets a `"[Truncated]": <omitted keys>` entry).
205
+ - Arrays, `Map` and `Set` are not walked past the 50th item: the omitted count
206
+ comes from `length` or `size`, so even a sparse array of length 2^32 - 1 is
207
+ cheap. An object's key list is built in full before the first 50 are kept
208
+ (JavaScript has no way to stop that early), so an object with millions of keys
209
+ costs one pass over its keys, but none of its values are serialized.
210
+
211
+ simplelog does not look for secrets. Tokens, passwords or personal data you put
212
+ in a message or in an argument are written as they are; redacting them is up to
213
+ the caller.
214
+
109
215
  ## Log Levels
110
216
 
111
217
  - `DEBUG`: Detailed information, typically of interest only when diagnosing
@@ -121,9 +227,8 @@ SDK or exporter for you.
121
227
  - `@murky-web/simplelog`: Node-first default entry
122
228
  - `@murky-web/simplelog/node`: explicit Node entry
123
229
  - `@murky-web/simplelog/bun`: Bun entry
124
- - `@murky-web/simplelog/deno`: Deno entry
125
230
  - `@murky-web/simplelog/web`: runtime-neutral console logger for fetch-style
126
- runtimes
231
+ runtimes, and a smaller one for browsers (see "In the browser")
127
232
  - `@murky-web/simplelog/hono`: Hono middleware for request-scoped logging
128
233
 
129
234
  For Bun, file appends intentionally use Bun's `node:fs` compatibility layer
@@ -136,10 +241,9 @@ For Hono-based servers and metaframeworks, prefer the runtime-neutral `web`
136
241
  logger together with the Hono middleware entry:
137
242
 
138
243
  ```typescript
139
- import { Hono } from "hono";
140
-
141
244
  import { createHonoLoggerMiddleware } from "@murky-web/simplelog/hono";
142
245
  import { Logger } from "@murky-web/simplelog/web";
246
+ import { Hono } from "hono";
143
247
 
144
248
  type AppVariables = {
145
249
  logger: Logger;
@@ -162,11 +266,22 @@ app.get("/", (c) => {
162
266
  The middleware exposes `c.var.logger`, and it logs request completion with
163
267
  method, path, status, duration, request ID, and Hono's runtime key.
164
268
 
269
+ The query string is not logged: query strings often carry tokens, OAuth codes
270
+ and e-mail addresses. If you need it, opt in with `includeQuery: true`; it then
271
+ appears as a separate `query` field (`"?q=cats&page=2"`) next to `path`:
272
+
273
+ ```typescript
274
+ app.use(createHonoLoggerMiddleware({ logger, includeQuery: true }));
275
+ ```
276
+
277
+ `hono` is an optional peer dependency. Only the `@murky-web/simplelog/hono`
278
+ entry imports it, so you need it installed only when you use the middleware.
279
+
165
280
  This adapter is intentionally thin:
166
281
 
167
282
  - it uses Hono's middleware and request context model
168
283
  - it creates a request-scoped child logger
169
- - it works across Node, Bun, Deno, Cloudflare, and Netlify style runtimes
284
+ - it works across Node, Bun, Cloudflare, and Netlify style runtimes
170
285
  - it does not own your tracing SDK or framework-specific SSR handoff
171
286
 
172
287
  If you want a custom request logger name, you can provide one directly or
@@ -183,6 +298,12 @@ app.use(
183
298
  );
184
299
  ```
185
300
 
301
+ The `context` has `method`, `path`, `query` (the query string with its leading
302
+ `?`, or `""`), `requestId`, `runtime` and `url`. The middleware itself logs
303
+ `query` only with `includeQuery: true`; a name you build from `context.query` or
304
+ `context.url` puts the query string into the log, so leave it out unless you
305
+ want that.
306
+
186
307
  ## Oxlint Integration
187
308
 
188
309
  `@murky-web/simplelog/oxlint` exports the SimpleLog-specific Oxlint JS plugin.
@@ -197,8 +318,22 @@ Current rules:
197
318
  - `simplelog/prefer-runtime-entry`
198
319
  - `simplelog/require-logger-name`
199
320
 
200
- If you use `@murky-web/config`, running `web-dev-config init --oxc --simplelog`
201
- wires this preset automatically.
321
+ Enable the plugin and the rules in your `.oxlintrc.jsonc`:
322
+
323
+ ```jsonc
324
+ {
325
+ "jsPlugins": ["@murky-web/simplelog/oxlint"],
326
+ "rules": {
327
+ "simplelog/prefer-simplelog": "error",
328
+ "simplelog/prefer-child-logger": "error",
329
+ "simplelog/no-ad-hoc-console-fallback": "error",
330
+ "simplelog/no-console-alias": "error",
331
+ "simplelog/prefer-hono-context-logger": "error",
332
+ "simplelog/prefer-runtime-entry": "error",
333
+ "simplelog/require-logger-name": "error",
334
+ },
335
+ }
336
+ ```
202
337
 
203
338
  ## OpenTelemetry Integration
204
339
 
@@ -0,0 +1,91 @@
1
+ import { formatConsoleTimestamp } from "./console_timestamp.js";
2
+ import { buildLogMessage, formatOpenTelemetryContextLabel } from "./logger_factory.js";
3
+ import { isError } from "./serialize_value.js";
4
+ // src/browser_console.ts
5
+ const EMPTY_LENGTH = 0;
6
+ const FIRST_DEPTH = 0;
7
+ const DEPTH_STEP = 1;
8
+ const FIRST_INDEX = 0;
9
+ const MAX_ERROR_DEPTH = 8;
10
+ const MAX_AGGREGATED_ERRORS = 50;
11
+ const MAX_DEPTH_LABEL = "[MaxDepth]";
12
+ const OBJECT_LABEL = "[Object]";
13
+ const LEVEL_STYLES = {
14
+ DEBUG: "color: #0891b2",
15
+ ERROR: "color: #dc2626",
16
+ INFO: "color: #16a34a",
17
+ WARN: "color: #ca8a04"
18
+ };
19
+ function readString(value, key, fallback) {
20
+ const property = Reflect.get(value, key);
21
+ if (typeof property === "string") return property;
22
+ return fallback;
23
+ }
24
+ /**
25
+ * Copies an Error with the text writer's allow-list only: `name`, `message`,
26
+ * `stack`, `cause`, `code` (a string or a number) and, for an `AggregateError`,
27
+ * `errors`. HTTP client errors (axios, got) carry the request, its headers and
28
+ * its body in other properties. The copy is a real Error, so DevTools still
29
+ * shows it with its stack.
30
+ *
31
+ * A `cause` or an element of `errors` is copied the same way when it is an
32
+ * Error; any other object becomes a label, as in the text writer's
33
+ * `serializeError`.
34
+ *
35
+ * @param {object} error - The Error.
36
+ * @param {number} depth - How deep in the Error chain it sits.
37
+ * @returns {unknown} The copy, or a label past the maximum depth.
38
+ */
39
+ function copyError(error, depth) {
40
+ if (depth > MAX_ERROR_DEPTH) return MAX_DEPTH_LABEL;
41
+ const copyChild = (value) => {
42
+ if (typeof value !== "object" || value === null) return value;
43
+ if (!isError(value)) return OBJECT_LABEL;
44
+ return copyError(value, depth + DEPTH_STEP);
45
+ };
46
+ const name = readString(error, "name", "Error");
47
+ const copy = new Error(readString(error, "message", ""));
48
+ const cause = Reflect.get(error, "cause");
49
+ const code = Reflect.get(error, "code");
50
+ const errors = Reflect.get(error, "errors");
51
+ copy.name = name;
52
+ copy.stack = readString(error, "stack", "");
53
+ if (typeof cause !== "undefined") copy.cause = copyChild(cause);
54
+ if (typeof code === "string" || typeof code === "number") Reflect.set(copy, "code", code);
55
+ if (name === "AggregateError" && Array.isArray(errors)) Reflect.set(copy, "errors", errors.slice(FIRST_INDEX, MAX_AGGREGATED_ERRORS).map((entry) => {
56
+ return copyChild(entry);
57
+ }));
58
+ return copy;
59
+ }
60
+ function toConsoleArgument(argument) {
61
+ if (typeof argument === "object" && argument !== null && isError(argument)) return copyError(argument, FIRST_DEPTH);
62
+ return argument;
63
+ }
64
+ /**
65
+ * The writer for browser DevTools. Arguments go to the console as they are, so
66
+ * objects stay expandable and DevTools colors values itself. Only the header is
67
+ * styled, with `%c` rather than ANSI codes, which Firefox does not render.
68
+ *
69
+ * The header is passed through `%s`, never as the format string itself: a `%`
70
+ * in a message or logger name would otherwise be read as a format specifier.
71
+ *
72
+ * An Error argument is copied with the text writer's allow-list (`copyError`),
73
+ * so a server bundle that resolves this writer by mistake does not print
74
+ * request headers either. Errors nested inside other objects are not walked:
75
+ * that needs the JSON serializer this writer leaves out.
76
+ *
77
+ * @param {LoggerConsole} loggerConsole - Where output goes.
78
+ * @returns {LogWriter} The runtime's `write`.
79
+ */
80
+ function createBrowserLogWriter(loggerConsole) {
81
+ return (entry, output) => {
82
+ const header = buildLogMessage(formatConsoleTimestamp(entry.epochMilliseconds, output.timestampFormat), `[${entry.level}]`, entry.loggerName, formatOpenTelemetryContextLabel(entry.openTelemetryContext), entry.message);
83
+ const args = entry.args.map(toConsoleArgument);
84
+ if (output.valueColorMode === "off") loggerConsole.log("%s", header, ...args);
85
+ else loggerConsole.log("%c%s", LEVEL_STYLES[entry.level], header, ...args);
86
+ if (entry.stackTrace.length > EMPTY_LENGTH) loggerConsole.error(entry.stackTrace);
87
+ };
88
+ }
89
+ export { createBrowserLogWriter };
90
+
91
+ //# sourceMappingURL=browser_console.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browser_console.js","names":[],"sources":["../src/browser_console.ts"],"sourcesContent":["import { formatConsoleTimestamp } from \"./console_timestamp\";\nimport {\n buildLogMessage,\n formatOpenTelemetryContextLabel,\n} from \"./logger_factory\";\nimport type { LoggerConsole, LogLevel, LogWriter } from \"./logger_factory\";\nimport { isError } from \"./serialize_value\";\n\nconst EMPTY_LENGTH = 0;\nconst FIRST_DEPTH = 0;\nconst DEPTH_STEP = 1;\nconst FIRST_INDEX = 0;\nconst MAX_ERROR_DEPTH = 8;\nconst MAX_AGGREGATED_ERRORS = 50;\nconst MAX_DEPTH_LABEL = \"[MaxDepth]\";\nconst OBJECT_LABEL = \"[Object]\";\n\n// CSS colors for the header, close to the ANSI colors of the text writer and\n// readable on the light and the dark DevTools theme.\nconst LEVEL_STYLES: Readonly<Record<LogLevel, string>> = {\n DEBUG: \"color: #0891b2\",\n ERROR: \"color: #dc2626\",\n INFO: \"color: #16a34a\",\n WARN: \"color: #ca8a04\",\n};\n\nfunction readString(value: object, key: string, fallback: string): string {\n const property: unknown = Reflect.get(value, key);\n\n if (typeof property === \"string\") {\n return property;\n }\n\n return fallback;\n}\n\n/**\n * Copies an Error with the text writer's allow-list only: `name`, `message`,\n * `stack`, `cause`, `code` (a string or a number) and, for an `AggregateError`,\n * `errors`. HTTP client errors (axios, got) carry the request, its headers and\n * its body in other properties. The copy is a real Error, so DevTools still\n * shows it with its stack.\n *\n * A `cause` or an element of `errors` is copied the same way when it is an\n * Error; any other object becomes a label, as in the text writer's\n * `serializeError`.\n *\n * @param {object} error - The Error.\n * @param {number} depth - How deep in the Error chain it sits.\n * @returns {unknown} The copy, or a label past the maximum depth.\n */\nfunction copyError(error: object, depth: number): unknown {\n if (depth > MAX_ERROR_DEPTH) {\n return MAX_DEPTH_LABEL;\n }\n\n const copyChild = (value: unknown): unknown => {\n if (typeof value !== \"object\" || value === null) {\n return value;\n }\n\n if (!isError(value)) {\n return OBJECT_LABEL;\n }\n\n return copyError(value, depth + DEPTH_STEP);\n };\n const name = readString(error, \"name\", \"Error\");\n const copy = new Error(readString(error, \"message\", \"\"));\n const cause: unknown = Reflect.get(error, \"cause\");\n const code: unknown = Reflect.get(error, \"code\");\n const errors: unknown = Reflect.get(error, \"errors\");\n\n copy.name = name;\n copy.stack = readString(error, \"stack\", \"\");\n\n if (typeof cause !== \"undefined\") {\n copy.cause = copyChild(cause);\n }\n\n if (typeof code === \"string\" || typeof code === \"number\") {\n Reflect.set(copy, \"code\", code);\n }\n\n if (name === \"AggregateError\" && Array.isArray(errors)) {\n Reflect.set(\n copy,\n \"errors\",\n errors\n .slice(FIRST_INDEX, MAX_AGGREGATED_ERRORS)\n .map((entry: unknown) => {\n return copyChild(entry);\n }),\n );\n }\n\n return copy;\n}\n\nfunction toConsoleArgument(argument: unknown): unknown {\n if (\n typeof argument === \"object\" &&\n argument !== null &&\n isError(argument)\n ) {\n return copyError(argument, FIRST_DEPTH);\n }\n\n return argument;\n}\n\n/**\n * The writer for browser DevTools. Arguments go to the console as they are, so\n * objects stay expandable and DevTools colors values itself. Only the header is\n * styled, with `%c` rather than ANSI codes, which Firefox does not render.\n *\n * The header is passed through `%s`, never as the format string itself: a `%`\n * in a message or logger name would otherwise be read as a format specifier.\n *\n * An Error argument is copied with the text writer's allow-list (`copyError`),\n * so a server bundle that resolves this writer by mistake does not print\n * request headers either. Errors nested inside other objects are not walked:\n * that needs the JSON serializer this writer leaves out.\n *\n * @param {LoggerConsole} loggerConsole - Where output goes.\n * @returns {LogWriter} The runtime's `write`.\n */\nfunction createBrowserLogWriter(loggerConsole: LoggerConsole): LogWriter {\n return (entry, output) => {\n const header = buildLogMessage(\n formatConsoleTimestamp(\n entry.epochMilliseconds,\n output.timestampFormat,\n ),\n `[${entry.level}]`,\n entry.loggerName,\n formatOpenTelemetryContextLabel(entry.openTelemetryContext),\n entry.message,\n );\n const args = entry.args.map(toConsoleArgument);\n\n if (output.valueColorMode === \"off\") {\n loggerConsole.log(\"%s\", header, ...args);\n } else {\n loggerConsole.log(\n \"%c%s\",\n LEVEL_STYLES[entry.level],\n header,\n ...args,\n );\n }\n\n if (entry.stackTrace.length > EMPTY_LENGTH) {\n loggerConsole.error(entry.stackTrace);\n }\n };\n}\n\nexport { createBrowserLogWriter };\n"],"mappings":";;;;AAQA,MAAM,eAAe;AACrB,MAAM,cAAc;AACpB,MAAM,aAAa;AACnB,MAAM,cAAc;AACpB,MAAM,kBAAkB;AACxB,MAAM,wBAAwB;AAC9B,MAAM,kBAAkB;AACxB,MAAM,eAAe;AAIrB,MAAM,eAAmD;CACrD,OAAO;CACP,OAAO;CACP,MAAM;CACN,MAAM;AACV;AAEA,SAAS,WAAW,OAAe,KAAa,UAA0B;CACtE,MAAM,WAAoB,QAAQ,IAAI,OAAO,GAAG;CAEhD,IAAI,OAAO,aAAa,UACpB,OAAO;CAGX,OAAO;AACX;;;;;;;;;;;;;;;;AAiBA,SAAS,UAAU,OAAe,OAAwB;CACtD,IAAI,QAAQ,iBACR,OAAO;CAGX,MAAM,aAAa,UAA4B;EAC3C,IAAI,OAAO,UAAU,YAAY,UAAU,MACvC,OAAO;EAGX,IAAI,CAAC,QAAQ,KAAK,GACd,OAAO;EAGX,OAAO,UAAU,OAAO,QAAQ,UAAU;CAC9C;CACA,MAAM,OAAO,WAAW,OAAO,QAAQ,OAAO;CAC9C,MAAM,OAAO,IAAI,MAAM,WAAW,OAAO,WAAW,EAAE,CAAC;CACvD,MAAM,QAAiB,QAAQ,IAAI,OAAO,OAAO;CACjD,MAAM,OAAgB,QAAQ,IAAI,OAAO,MAAM;CAC/C,MAAM,SAAkB,QAAQ,IAAI,OAAO,QAAQ;CAEnD,KAAK,OAAO;CACZ,KAAK,QAAQ,WAAW,OAAO,SAAS,EAAE;CAE1C,IAAI,OAAO,UAAU,aACjB,KAAK,QAAQ,UAAU,KAAK;CAGhC,IAAI,OAAO,SAAS,YAAY,OAAO,SAAS,UAC5C,QAAQ,IAAI,MAAM,QAAQ,IAAI;CAGlC,IAAI,SAAS,oBAAoB,MAAM,QAAQ,MAAM,GACjD,QAAQ,IACJ,MACA,UACA,OACK,MAAM,aAAa,qBAAqB,CAAC,CACzC,KAAK,UAAmB;EACrB,OAAO,UAAU,KAAK;CAC1B,CAAC,CACT;CAGJ,OAAO;AACX;AAEA,SAAS,kBAAkB,UAA4B;CACnD,IACI,OAAO,aAAa,YACpB,aAAa,QACb,QAAQ,QAAQ,GAEhB,OAAO,UAAU,UAAU,WAAW;CAG1C,OAAO;AACX;;;;;;;;;;;;;;;;;AAkBA,SAAS,uBAAuB,eAAyC;CACrE,QAAQ,OAAO,WAAW;EACtB,MAAM,SAAS,gBACX,uBACI,MAAM,mBACN,OAAO,eACX,GACA,IAAI,MAAM,MAAM,IAChB,MAAM,YACN,gCAAgC,MAAM,oBAAoB,GAC1D,MAAM,OACV;EACA,MAAM,OAAO,MAAM,KAAK,IAAI,iBAAiB;EAE7C,IAAI,OAAO,mBAAmB,OAC1B,cAAc,IAAI,MAAM,QAAQ,GAAG,IAAI;OAEvC,cAAc,IACV,QACA,aAAa,MAAM,QACnB,QACA,GAAG,IACP;EAGJ,IAAI,MAAM,WAAW,SAAS,cAC1B,cAAc,MAAM,MAAM,UAAU;CAE5C;AACJ"}
@@ -1,8 +1,6 @@
1
1
  import { LogLevel, LoggerBase, LoggerOptions, LoggerParent } from "./logger_factory.js";
2
- //#region src/deno_logger.d.ts
3
2
  declare class Logger extends LoggerBase {
4
3
  constructor(name: string, parent?: LoggerParent, options?: LoggerOptions);
5
4
  }
6
- //#endregion
7
5
  export { type LogLevel, Logger, type LoggerOptions };
8
- //# sourceMappingURL=deno_logger.d.ts.map
6
+ //# sourceMappingURL=browser_logger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browser_logger.d.ts","names":[],"sources":["../src/browser_logger.ts"],"mappings":";cAkBM,eAAe;EACjB,YACI,cACA,SAAS,cACT,UAAS"}
@@ -0,0 +1,17 @@
1
+ import { createBrowserLogWriter } from "./browser_console.js";
2
+ import { LoggerBase, createLoggerConsole } from "./logger_factory.js";
3
+ // src/browser_logger.ts
4
+ /**
5
+ * What `@murky-web/simplelog/web` resolves to under the `browser` export
6
+ * condition. Same API as the `web` logger; see `createBrowserLogWriter` for how
7
+ * the output differs.
8
+ */
9
+ const browserRuntime = { write: createBrowserLogWriter(createLoggerConsole()) };
10
+ var Logger = class Logger extends LoggerBase {
11
+ constructor(name, parent, options = {}) {
12
+ super(Logger, browserRuntime, name, parent, options);
13
+ }
14
+ };
15
+ export { Logger };
16
+
17
+ //# sourceMappingURL=browser_logger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browser_logger.js","names":[],"sources":["../src/browser_logger.ts"],"sourcesContent":["import { createBrowserLogWriter } from \"./browser_console\";\nimport { LoggerBase, createLoggerConsole } from \"./logger_factory\";\nimport type {\n LoggerOptions,\n LoggerParent,\n LoggerRuntime,\n LogLevel,\n} from \"./logger_factory\";\n\n/**\n * What `@murky-web/simplelog/web` resolves to under the `browser` export\n * condition. Same API as the `web` logger; see `createBrowserLogWriter` for how\n * the output differs.\n */\nconst browserRuntime = {\n write: createBrowserLogWriter(createLoggerConsole()),\n} satisfies LoggerRuntime;\n\nclass Logger extends LoggerBase {\n constructor(\n name: string,\n parent?: LoggerParent,\n options: LoggerOptions = {},\n ) {\n super(Logger, browserRuntime, name, parent, options);\n }\n}\n\nexport { Logger };\n\nexport type { LoggerOptions, LogLevel };\n"],"mappings":";;;;;;;;AAcA,MAAM,iBAAiB,EACnB,OAAO,uBAAuB,oBAAoB,CAAC,EACvD;AAEA,IAAM,SAAN,MAAM,eAAe,WAAW;CAC5B,YACI,MACA,QACA,UAAyB,CAAC,GAC5B;EACE,MAAM,QAAQ,gBAAgB,MAAM,QAAQ,OAAO;CACvD;AACJ"}
@@ -1,8 +1,6 @@
1
1
  import { LogLevel, LoggerBase, LoggerOptions, LoggerParent } from "./logger_factory.js";
2
- //#region src/bun_logger.d.ts
3
2
  declare class Logger extends LoggerBase {
4
3
  constructor(name: string, parent?: LoggerParent, options?: LoggerOptions);
5
4
  }
6
- //#endregion
7
5
  export { type LogLevel, Logger, type LoggerOptions };
8
6
  //# sourceMappingURL=bun_logger.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"bun_logger.d.ts","names":[],"sources":["../src/bun_logger.ts"],"mappings":";;cAIM,eAAe;EACnB,YACE,cACA,SAAS,cACT,UAAS"}
1
+ {"version":3,"file":"bun_logger.d.ts","names":[],"sources":["../src/bun_logger.ts"],"mappings":";cAIM,eAAe;EACjB,YACI,cACA,SAAS,cACT,UAAS"}
@@ -1,12 +1,11 @@
1
1
  import { LoggerBase } from "./logger_factory.js";
2
2
  import { nodeRuntime } from "./node_runtime.js";
3
- //#region src/bun_logger.ts
3
+ // src/bun_logger.ts
4
4
  var Logger = class Logger extends LoggerBase {
5
5
  constructor(name, parent, options = {}) {
6
6
  super(Logger, nodeRuntime, name, parent, options);
7
7
  }
8
8
  };
9
- //#endregion
10
9
  export { Logger };
11
10
 
12
11
  //# sourceMappingURL=bun_logger.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"bun_logger.js","names":["bunRuntime"],"sources":["../src/bun_logger.ts"],"sourcesContent":["import { nodeRuntime as bunRuntime } from \"./node_runtime\";\nimport { LoggerBase } from \"./logger_factory\";\nimport type { LoggerOptions, LoggerParent, LogLevel } from \"./logger_factory\";\n\nclass Logger extends LoggerBase {\n constructor(\n name: string,\n parent?: LoggerParent,\n options: LoggerOptions = {},\n ) {\n super(Logger, bunRuntime, name, parent, options);\n }\n}\n\nexport { Logger };\n\nexport type { LoggerOptions, LogLevel };\n"],"mappings":";;;AAIA,IAAM,SAAN,MAAM,eAAe,WAAW;CAC9B,YACE,MACA,QACA,UAAyB,CAAC,GAC1B;EACA,MAAM,QAAQA,aAAY,MAAM,QAAQ,OAAO;CACjD;AACF"}
1
+ {"version":3,"file":"bun_logger.js","names":["bunRuntime"],"sources":["../src/bun_logger.ts"],"sourcesContent":["import { LoggerBase } from \"./logger_factory\";\nimport type { LoggerOptions, LoggerParent, LogLevel } from \"./logger_factory\";\nimport { nodeRuntime as bunRuntime } from \"./node_runtime\";\n\nclass Logger extends LoggerBase {\n constructor(\n name: string,\n parent?: LoggerParent,\n options: LoggerOptions = {},\n ) {\n super(Logger, bunRuntime, name, parent, options);\n }\n}\n\nexport { Logger };\n\nexport type { LoggerOptions, LogLevel };\n"],"mappings":";;;AAIA,IAAM,SAAN,MAAM,eAAe,WAAW;CAC5B,YACI,MACA,QACA,UAAyB,CAAC,GAC5B;EACE,MAAM,QAAQA,aAAY,MAAM,QAAQ,OAAO;CACnD;AACJ"}
@@ -0,0 +1,45 @@
1
+ // src/console_defaults.ts
2
+ const FORCE_COLOR_DISABLED = /* @__PURE__ */ new Set(["0", "false"]);
3
+ /**
4
+ * `NO_COLOR` as https://no-color.org defines it wins, then `FORCE_COLOR` with
5
+ * Node's values (`0` and `false` mean off, anything else, even empty, means
6
+ * on), then whether stdout is a terminal.
7
+ *
8
+ * @param {ConsoleEnvironment} environment - The raw environment.
9
+ * @returns {ValueColorMode} `"level"` for colors, `"off"` for plain text.
10
+ */
11
+ function resolveDefaultValueColorMode(environment) {
12
+ if (typeof environment.noColor === "string" && environment.noColor !== "") return "off";
13
+ if (typeof environment.forceColor === "string") {
14
+ if (FORCE_COLOR_DISABLED.has(environment.forceColor)) return "off";
15
+ return "level";
16
+ }
17
+ if (environment.stdoutIsTerminal) return "level";
18
+ return "off";
19
+ }
20
+ function parseTimestampFormat(value) {
21
+ if (value === "iso" || value === "time") return value;
22
+ }
23
+ /**
24
+ * The time of day is enough to read along in a terminal; a pipe usually ends in
25
+ * a file, CI or a log service, where the date is needed. `SIMPLELOG_TIMESTAMP`
26
+ * overrides that for pipes that are read by people (a process manager's TUI).
27
+ *
28
+ * @param {ConsoleEnvironment} environment - The raw environment.
29
+ * @returns {TimestampFormat} The console timestamp format.
30
+ */
31
+ function resolveDefaultTimestampFormat(environment) {
32
+ const override = parseTimestampFormat(environment.simplelogTimestamp);
33
+ if (override !== void 0) return override;
34
+ if (environment.stdoutIsTerminal) return "time";
35
+ return "iso";
36
+ }
37
+ function resolveConsoleDefaults(environment) {
38
+ return {
39
+ timestampFormat: resolveDefaultTimestampFormat(environment),
40
+ valueColorMode: resolveDefaultValueColorMode(environment)
41
+ };
42
+ }
43
+ export { resolveConsoleDefaults };
44
+
45
+ //# sourceMappingURL=console_defaults.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"console_defaults.js","names":[],"sources":["../src/console_defaults.ts"],"sourcesContent":["import type {\n ConsoleDefaults,\n TimestampFormat,\n ValueColorMode,\n} from \"./logger_factory\";\n\n/**\n * What a runtime knows about where its console output goes, read raw from the\n * environment. The Node and Bun runtime fills it in; this module turns it into\n * defaults and never touches `process` itself, so it stays safe for the browser\n * build.\n */\ntype ConsoleEnvironment = Readonly<{\n forceColor: string | undefined;\n noColor: string | undefined;\n simplelogTimestamp: string | undefined;\n stdoutIsTerminal: boolean;\n}>;\n\nconst FORCE_COLOR_DISABLED = new Set([\"0\", \"false\"]);\n\n/**\n * `NO_COLOR` as https://no-color.org defines it wins, then `FORCE_COLOR` with\n * Node's values (`0` and `false` mean off, anything else, even empty, means\n * on), then whether stdout is a terminal.\n *\n * @param {ConsoleEnvironment} environment - The raw environment.\n * @returns {ValueColorMode} `\"level\"` for colors, `\"off\"` for plain text.\n */\nfunction resolveDefaultValueColorMode(\n environment: ConsoleEnvironment,\n): ValueColorMode {\n if (typeof environment.noColor === \"string\" && environment.noColor !== \"\") {\n return \"off\";\n }\n\n if (typeof environment.forceColor === \"string\") {\n if (FORCE_COLOR_DISABLED.has(environment.forceColor)) {\n return \"off\";\n }\n\n return \"level\";\n }\n\n if (environment.stdoutIsTerminal) {\n return \"level\";\n }\n\n return \"off\";\n}\n\nfunction parseTimestampFormat(\n value: string | undefined,\n): TimestampFormat | undefined {\n if (value === \"iso\" || value === \"time\") {\n return value;\n }\n\n return undefined;\n}\n\n/**\n * The time of day is enough to read along in a terminal; a pipe usually ends in\n * a file, CI or a log service, where the date is needed. `SIMPLELOG_TIMESTAMP`\n * overrides that for pipes that are read by people (a process manager's TUI).\n *\n * @param {ConsoleEnvironment} environment - The raw environment.\n * @returns {TimestampFormat} The console timestamp format.\n */\nfunction resolveDefaultTimestampFormat(\n environment: ConsoleEnvironment,\n): TimestampFormat {\n const override = parseTimestampFormat(environment.simplelogTimestamp);\n\n if (override !== undefined) {\n return override;\n }\n\n if (environment.stdoutIsTerminal) {\n return \"time\";\n }\n\n return \"iso\";\n}\n\nfunction resolveConsoleDefaults(\n environment: ConsoleEnvironment,\n): ConsoleDefaults {\n return {\n timestampFormat: resolveDefaultTimestampFormat(environment),\n valueColorMode: resolveDefaultValueColorMode(environment),\n };\n}\n\nexport { resolveConsoleDefaults };\nexport type { ConsoleEnvironment };\n"],"mappings":";AAmBA,MAAM,uCAAuB,IAAI,IAAI,CAAC,KAAK,OAAO,CAAC;;;;;;;;;AAUnD,SAAS,6BACL,aACc;CACd,IAAI,OAAO,YAAY,YAAY,YAAY,YAAY,YAAY,IACnE,OAAO;CAGX,IAAI,OAAO,YAAY,eAAe,UAAU;EAC5C,IAAI,qBAAqB,IAAI,YAAY,UAAU,GAC/C,OAAO;EAGX,OAAO;CACX;CAEA,IAAI,YAAY,kBACZ,OAAO;CAGX,OAAO;AACX;AAEA,SAAS,qBACL,OAC2B;CAC3B,IAAI,UAAU,SAAS,UAAU,QAC7B,OAAO;AAIf;;;;;;;;;AAUA,SAAS,8BACL,aACe;CACf,MAAM,WAAW,qBAAqB,YAAY,kBAAkB;CAEpE,IAAI,aAAa,KAAA,GACb,OAAO;CAGX,IAAI,YAAY,kBACZ,OAAO;CAGX,OAAO;AACX;AAEA,SAAS,uBACL,aACe;CACf,OAAO;EACH,iBAAiB,8BAA8B,WAAW;EAC1D,gBAAgB,6BAA6B,WAAW;CAC5D;AACJ"}
@@ -0,0 +1,25 @@
1
+ import { LogFileWriter } from "./log_file.js";
2
+ import { LogWriter, LoggerConsole } from "./logger_factory.js";
3
+ type StringifiedArgument = Readonly<{
4
+ /**
5
+ * The JSON-safe value behind an object's `text`. The log file writes it as
6
+ * compact JSON; it is only serialized again when a file is written.
7
+ */
8
+ jsonValue?: unknown;
9
+ kind: StringifiedArgumentKind;
10
+ text: string;
11
+ }>;
12
+ type StringifiedArgumentKind = "boolean" | "function" | "nullish" | "number" | "object" | "string" | "symbol";
13
+ /**
14
+ * The writer for terminals and server logs: every argument is turned into text
15
+ * (objects as JSON, with the safety rules of `toJsonSafeValue`), colored with
16
+ * ANSI codes unless `valueColorMode` is `"off"`.
17
+ *
18
+ * @param {LoggerConsole} loggerConsole - Where console output goes.
19
+ * @param {LogFileWriter} [writeLogFile] - Writes the log file; only runtimes
20
+ * that can write files pass one.
21
+ * @returns {LogWriter} The runtime's `write`.
22
+ */
23
+ declare function createTextLogWriter(loggerConsole: LoggerConsole, writeLogFile?: LogFileWriter): LogWriter;
24
+ export { type StringifiedArgument, createTextLogWriter };
25
+ //# sourceMappingURL=console_text.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"console_text.d.ts","names":[],"sources":["../src/console_text.ts"],"mappings":";;KAqCK,sBAAsB;;;;;EAKvB;EACA,MAAM;EACN;;KAGC;;;;;;;;;;;iBAmUI,oBACL,eAAe,eACf,eAAe,gBAChB"}