@murky-web/simplelog 3.0.0 → 3.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +35 -10
- package/dist/browser_console.js +91 -0
- package/dist/browser_console.js.map +1 -0
- package/dist/browser_logger.d.ts +6 -0
- package/dist/browser_logger.d.ts.map +1 -0
- package/dist/browser_logger.js +17 -0
- package/dist/browser_logger.js.map +1 -0
- package/dist/bun_logger.js.map +1 -1
- package/dist/console_defaults.js.map +1 -1
- package/dist/console_text.d.ts +25 -0
- package/dist/console_text.d.ts.map +1 -0
- package/dist/console_text.js +168 -0
- package/dist/console_text.js.map +1 -0
- package/dist/console_timestamp.js.map +1 -1
- package/dist/hono_middleware.d.ts +2 -2
- package/dist/hono_middleware.js.map +1 -1
- package/dist/log_file.d.ts +9 -0
- package/dist/log_file.d.ts.map +1 -0
- package/dist/log_file.js +52 -0
- package/dist/log_file.js.map +1 -0
- package/dist/logger.js.map +1 -1
- package/dist/logger_factory.d.ts +30 -10
- package/dist/logger_factory.d.ts.map +1 -1
- package/dist/logger_factory.js +26 -240
- package/dist/logger_factory.js.map +1 -1
- package/dist/node_runtime.js +5 -4
- package/dist/node_runtime.js.map +1 -1
- package/dist/otel.js.map +1 -1
- package/dist/serialize_value.d.ts +44 -0
- package/dist/serialize_value.d.ts.map +1 -0
- package/dist/serialize_value.js +1 -1
- package/dist/serialize_value.js.map +1 -1
- package/dist/web_logger.d.ts.map +1 -1
- package/dist/web_logger.js +2 -1
- package/dist/web_logger.js.map +1 -1
- package/oxlint/index.mjs +3 -3
- package/oxlint/no-ad-hoc-console-fallback.mjs +6 -6
- package/oxlint/no-console-alias.mjs +7 -7
- package/oxlint/prefer-child-logger.mjs +7 -7
- package/oxlint/prefer-hono-context-logger.mjs +7 -7
- package/oxlint/prefer-runtime-entry.mjs +6 -6
- package/oxlint/prefer-simplelog.mjs +8 -8
- package/oxlint/require-logger-name.mjs +7 -7
- package/oxlint/utils.mjs +3 -3
- package/package.json +11 -3
package/README.md
CHANGED
|
@@ -33,7 +33,7 @@ const logger = new Logger("MyLogger", undefined, {
|
|
|
33
33
|
writeToFile: true,
|
|
34
34
|
logFilePath: "logs/mylogger.log",
|
|
35
35
|
logLevelThreshold: "DEBUG",
|
|
36
|
-
valueColorMode: "syntax"
|
|
36
|
+
valueColorMode: "syntax"
|
|
37
37
|
});
|
|
38
38
|
```
|
|
39
39
|
|
|
@@ -131,6 +131,31 @@ An explicit option always wins over the environment. Log files always get the
|
|
|
131
131
|
ISO timestamp and never colors, whatever the console shows. The `web` entry has
|
|
132
132
|
no terminal to ask: it keeps `"level"` and `"iso"`.
|
|
133
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 an
|
|
154
|
+
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
|
+
|
|
134
159
|
`includeOpenTelemetryContext` is intentionally opt-in. When enabled, `simplelog`
|
|
135
160
|
reads the current active span from `@opentelemetry/api` and appends `trace_id`
|
|
136
161
|
and `span_id` to console and file output. It does not install an OpenTelemetry
|
|
@@ -203,7 +228,7 @@ the caller.
|
|
|
203
228
|
- `@murky-web/simplelog/node`: explicit Node entry
|
|
204
229
|
- `@murky-web/simplelog/bun`: Bun entry
|
|
205
230
|
- `@murky-web/simplelog/web`: runtime-neutral console logger for fetch-style
|
|
206
|
-
runtimes
|
|
231
|
+
runtimes, and a smaller one for browsers (see "In the browser")
|
|
207
232
|
- `@murky-web/simplelog/hono`: Hono middleware for request-scoped logging
|
|
208
233
|
|
|
209
234
|
For Bun, file appends intentionally use Bun's `node:fs` compatibility layer
|
|
@@ -227,7 +252,7 @@ type AppVariables = {
|
|
|
227
252
|
const app = new Hono<{ Variables: AppVariables }>();
|
|
228
253
|
const logger = new Logger("server", undefined, {
|
|
229
254
|
includeOpenTelemetryContext: true,
|
|
230
|
-
valueColorMode: "off"
|
|
255
|
+
valueColorMode: "off"
|
|
231
256
|
});
|
|
232
257
|
|
|
233
258
|
app.use(createHonoLoggerMiddleware({ logger }));
|
|
@@ -268,8 +293,8 @@ app.use(
|
|
|
268
293
|
logger,
|
|
269
294
|
requestLoggerName(context) {
|
|
270
295
|
return `${context.runtime}:${context.path}`;
|
|
271
|
-
}
|
|
272
|
-
})
|
|
296
|
+
}
|
|
297
|
+
})
|
|
273
298
|
);
|
|
274
299
|
```
|
|
275
300
|
|
|
@@ -305,8 +330,8 @@ Enable the plugin and the rules in your `.oxlintrc.jsonc`:
|
|
|
305
330
|
"simplelog/no-console-alias": "error",
|
|
306
331
|
"simplelog/prefer-hono-context-logger": "error",
|
|
307
332
|
"simplelog/prefer-runtime-entry": "error",
|
|
308
|
-
"simplelog/require-logger-name": "error"
|
|
309
|
-
}
|
|
333
|
+
"simplelog/require-logger-name": "error"
|
|
334
|
+
}
|
|
310
335
|
}
|
|
311
336
|
```
|
|
312
337
|
|
|
@@ -329,7 +354,7 @@ import { Logger } from "@murky-web/simplelog/web";
|
|
|
329
354
|
|
|
330
355
|
const logger = new Logger("server", undefined, {
|
|
331
356
|
includeOpenTelemetryContext: true,
|
|
332
|
-
valueColorMode: "off"
|
|
357
|
+
valueColorMode: "off"
|
|
333
358
|
});
|
|
334
359
|
```
|
|
335
360
|
|
|
@@ -374,12 +399,12 @@ import { Logger } from "@murky-web/simplelog";
|
|
|
374
399
|
const logger = new Logger("AppLogger", undefined, {
|
|
375
400
|
writeToFile: true,
|
|
376
401
|
logFilePath: "logs/app.log",
|
|
377
|
-
logLevelThreshold: "INFO"
|
|
402
|
+
logLevelThreshold: "INFO"
|
|
378
403
|
});
|
|
379
404
|
|
|
380
405
|
logger.info("Application started");
|
|
381
406
|
logger.debug(
|
|
382
|
-
"This debug message will not be logged because the threshold is INFO"
|
|
407
|
+
"This debug message will not be logged because the threshold is INFO"
|
|
383
408
|
);
|
|
384
409
|
logger.warn("This is a warning");
|
|
385
410
|
logger.error("This is an error");
|
|
@@ -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"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { LogLevel, LoggerBase, LoggerOptions, LoggerParent } from "./logger_factory.js";
|
|
2
|
+
declare class Logger extends LoggerBase {
|
|
3
|
+
constructor(name: string, parent?: LoggerParent, options?: LoggerOptions);
|
|
4
|
+
}
|
|
5
|
+
export { type LogLevel, Logger, type LoggerOptions };
|
|
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"}
|
package/dist/bun_logger.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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 = {}
|
|
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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"console_defaults.js","names":[],"sources":["../src/console_defaults.ts"],"sourcesContent":["import type {\n ConsoleDefaults,\n TimestampFormat,\n ValueColorMode
|
|
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"}
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { formatConsoleTimestamp } from "./console_timestamp.js";
|
|
2
|
+
import { buildLogMessage, formatOpenTelemetryContextLabel } from "./logger_factory.js";
|
|
3
|
+
import { formatFunctionLabel, toJsonSafeValue } from "./serialize_value.js";
|
|
4
|
+
// src/console_text.ts
|
|
5
|
+
const ANSI_RESET_COLOR = 0;
|
|
6
|
+
const ANSI_GREEN = 32;
|
|
7
|
+
const ANSI_YELLOW = 33;
|
|
8
|
+
const ANSI_RED = 31;
|
|
9
|
+
const ANSI_CYAN = 36;
|
|
10
|
+
const ANSI_BLUE = 34;
|
|
11
|
+
const ANSI_MAGENTA = 35;
|
|
12
|
+
const ANSI_GRAY = 90;
|
|
13
|
+
const EMPTY_LENGTH = 0;
|
|
14
|
+
const JSON_INDENTATION = 2;
|
|
15
|
+
const FALLBACK_OBJECT_STRING = "[Object]";
|
|
16
|
+
const LOG_LEVEL_COLORS = {
|
|
17
|
+
DEBUG: ANSI_CYAN,
|
|
18
|
+
ERROR: ANSI_RED,
|
|
19
|
+
INFO: ANSI_GREEN,
|
|
20
|
+
WARN: ANSI_YELLOW
|
|
21
|
+
};
|
|
22
|
+
function colorize(text, colorCode) {
|
|
23
|
+
return `\u001B[${colorCode}m${text}\u001B[${ANSI_RESET_COLOR}m`;
|
|
24
|
+
}
|
|
25
|
+
function isPrimitiveArgument(argument) {
|
|
26
|
+
return typeof argument === "bigint" || typeof argument === "boolean" || typeof argument === "number" || typeof argument === "string" || typeof argument === "symbol";
|
|
27
|
+
}
|
|
28
|
+
function stringifyPrimitiveArgument(argument) {
|
|
29
|
+
if (typeof argument === "string") return {
|
|
30
|
+
kind: "string",
|
|
31
|
+
text: argument
|
|
32
|
+
};
|
|
33
|
+
if (typeof argument === "symbol") return {
|
|
34
|
+
kind: "symbol",
|
|
35
|
+
text: argument.toString()
|
|
36
|
+
};
|
|
37
|
+
if (typeof argument === "boolean") return {
|
|
38
|
+
kind: "boolean",
|
|
39
|
+
text: `${argument}`
|
|
40
|
+
};
|
|
41
|
+
return {
|
|
42
|
+
kind: "number",
|
|
43
|
+
text: `${argument}`
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
function stringifyFunctionArgument(functionName) {
|
|
47
|
+
return {
|
|
48
|
+
kind: "function",
|
|
49
|
+
text: formatFunctionLabel(functionName)
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
function stringifyJsonArgument(argument) {
|
|
53
|
+
try {
|
|
54
|
+
const safeValue = toJsonSafeValue(argument);
|
|
55
|
+
const stringifiedArgument = JSON.stringify(safeValue, void 0, JSON_INDENTATION);
|
|
56
|
+
if (typeof stringifiedArgument !== "string") return {
|
|
57
|
+
kind: "object",
|
|
58
|
+
text: FALLBACK_OBJECT_STRING
|
|
59
|
+
};
|
|
60
|
+
return {
|
|
61
|
+
jsonValue: safeValue,
|
|
62
|
+
kind: "object",
|
|
63
|
+
text: stringifiedArgument
|
|
64
|
+
};
|
|
65
|
+
} catch {
|
|
66
|
+
return {
|
|
67
|
+
kind: "object",
|
|
68
|
+
text: FALLBACK_OBJECT_STRING
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
function stringifyArgument(argument) {
|
|
73
|
+
if (typeof argument === "undefined") return {
|
|
74
|
+
kind: "nullish",
|
|
75
|
+
text: "undefined"
|
|
76
|
+
};
|
|
77
|
+
if (argument === null) return {
|
|
78
|
+
kind: "nullish",
|
|
79
|
+
text: "null"
|
|
80
|
+
};
|
|
81
|
+
if (isPrimitiveArgument(argument)) return stringifyPrimitiveArgument(argument);
|
|
82
|
+
if (typeof argument === "function") return stringifyFunctionArgument(argument.name);
|
|
83
|
+
return stringifyJsonArgument(argument);
|
|
84
|
+
}
|
|
85
|
+
function stringifyArguments(argumentsList) {
|
|
86
|
+
return argumentsList.map((argument) => {
|
|
87
|
+
return stringifyArgument(argument);
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
function buildColoredLogMessage(level, timestamp, loggerName, openTelemetryContextLabel, message) {
|
|
91
|
+
const colorCode = LOG_LEVEL_COLORS[level];
|
|
92
|
+
return buildLogMessage(colorize(timestamp, colorCode), colorize(`[${level}]`, colorCode), colorize(loggerName, colorCode), openTelemetryContextLabel, colorize(message, colorCode));
|
|
93
|
+
}
|
|
94
|
+
function colorizeOpenTelemetryContextLabel(level, openTelemetryContext, valueColorMode) {
|
|
95
|
+
const plainOpenTelemetryContextLabel = formatOpenTelemetryContextLabel(openTelemetryContext);
|
|
96
|
+
if (valueColorMode === "off" || plainOpenTelemetryContextLabel.length === EMPTY_LENGTH) return plainOpenTelemetryContextLabel;
|
|
97
|
+
if (valueColorMode === "syntax") return colorize(plainOpenTelemetryContextLabel, ANSI_GRAY);
|
|
98
|
+
return colorize(plainOpenTelemetryContextLabel, LOG_LEVEL_COLORS[level]);
|
|
99
|
+
}
|
|
100
|
+
function getSyntaxColorCode(kind) {
|
|
101
|
+
switch (kind) {
|
|
102
|
+
case "boolean": return ANSI_YELLOW;
|
|
103
|
+
case "function": return ANSI_MAGENTA;
|
|
104
|
+
case "nullish": return ANSI_GRAY;
|
|
105
|
+
case "number": return ANSI_CYAN;
|
|
106
|
+
case "object": return ANSI_BLUE;
|
|
107
|
+
case "string": return ANSI_GREEN;
|
|
108
|
+
case "symbol": return ANSI_MAGENTA;
|
|
109
|
+
default: return ANSI_GREEN;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
function colorizeArguments(argumentsList, level, valueColorMode) {
|
|
113
|
+
if (valueColorMode === "off") return argumentsList.map((argument) => {
|
|
114
|
+
return argument.text;
|
|
115
|
+
});
|
|
116
|
+
if (valueColorMode === "syntax") return argumentsList.map((argument) => {
|
|
117
|
+
return colorize(argument.text, getSyntaxColorCode(argument.kind));
|
|
118
|
+
});
|
|
119
|
+
const colorCode = LOG_LEVEL_COLORS[level];
|
|
120
|
+
return argumentsList.map((argument) => {
|
|
121
|
+
return colorize(argument.text, colorCode);
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
function buildPlainConsoleLogMessage(level, timestamp, loggerName, openTelemetryContext, message) {
|
|
125
|
+
return buildLogMessage(timestamp, `[${level}]`, loggerName, formatOpenTelemetryContextLabel(openTelemetryContext), message);
|
|
126
|
+
}
|
|
127
|
+
function buildConsoleLogMessage(level, timestamp, loggerName, openTelemetryContext, message, valueColorMode) {
|
|
128
|
+
if (valueColorMode === "off") return buildPlainConsoleLogMessage(level, timestamp, loggerName, openTelemetryContext, message);
|
|
129
|
+
return buildColoredLogMessage(level, timestamp, loggerName, colorizeOpenTelemetryContextLabel(level, openTelemetryContext, valueColorMode), message);
|
|
130
|
+
}
|
|
131
|
+
function buildConsoleStackTrace(stackTrace, level, valueColorMode) {
|
|
132
|
+
if (valueColorMode === "off") return stackTrace;
|
|
133
|
+
return colorize(stackTrace, LOG_LEVEL_COLORS[level]);
|
|
134
|
+
}
|
|
135
|
+
function createConsolePayload(entry, args, output) {
|
|
136
|
+
const { level } = entry;
|
|
137
|
+
const { valueColorMode } = output;
|
|
138
|
+
return {
|
|
139
|
+
consoleArgs: colorizeArguments(args, level, valueColorMode),
|
|
140
|
+
consoleLogMessage: buildConsoleLogMessage(level, formatConsoleTimestamp(entry.epochMilliseconds, output.timestampFormat), entry.loggerName, entry.openTelemetryContext, entry.message, valueColorMode),
|
|
141
|
+
consoleStackTrace: buildConsoleStackTrace(entry.stackTrace, level, valueColorMode)
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* The writer for terminals and server logs: every argument is turned into text
|
|
146
|
+
* (objects as JSON, with the safety rules of `toJsonSafeValue`), colored with
|
|
147
|
+
* ANSI codes unless `valueColorMode` is `"off"`.
|
|
148
|
+
*
|
|
149
|
+
* @param {LoggerConsole} loggerConsole - Where console output goes.
|
|
150
|
+
* @param {LogFileWriter} [writeLogFile] - Writes the log file; only runtimes
|
|
151
|
+
* that can write files pass one.
|
|
152
|
+
* @returns {LogWriter} The runtime's `write`.
|
|
153
|
+
*/
|
|
154
|
+
function createTextLogWriter(loggerConsole, writeLogFile) {
|
|
155
|
+
return (entry, output) => {
|
|
156
|
+
const args = stringifyArguments(entry.args);
|
|
157
|
+
if (output.writeToFile && typeof writeLogFile === "function") writeLogFile(output.logFilePath, {
|
|
158
|
+
...entry,
|
|
159
|
+
args
|
|
160
|
+
});
|
|
161
|
+
const payload = createConsolePayload(entry, args, output);
|
|
162
|
+
loggerConsole.log(payload.consoleLogMessage, ...payload.consoleArgs);
|
|
163
|
+
if (entry.stackTrace.length > EMPTY_LENGTH) loggerConsole.error(payload.consoleStackTrace);
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
export { createTextLogWriter };
|
|
167
|
+
|
|
168
|
+
//# sourceMappingURL=console_text.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"console_text.js","names":[],"sources":["../src/console_text.ts"],"sourcesContent":["import { formatConsoleTimestamp } from \"./console_timestamp\";\nimport type { LogFileWriter } from \"./log_file\";\nimport {\n buildLogMessage,\n formatOpenTelemetryContextLabel\n} from \"./logger_factory\";\nimport type {\n LogEntry,\n LoggerConsole,\n LogLevel,\n LogOutput,\n LogWriter,\n OpenTelemetryContext,\n ValueColorMode\n} from \"./logger_factory\";\nimport { formatFunctionLabel, toJsonSafeValue } from \"./serialize_value\";\n\nconst ANSI_RESET_COLOR = 0;\nconst ANSI_GREEN = 32;\nconst ANSI_YELLOW = 33;\nconst ANSI_RED = 31;\nconst ANSI_CYAN = 36;\nconst ANSI_BLUE = 34;\nconst ANSI_MAGENTA = 35;\nconst ANSI_GRAY = 90;\nconst EMPTY_LENGTH = 0;\nconst JSON_INDENTATION = 2;\nconst FALLBACK_OBJECT_STRING = \"[Object]\";\n\ntype ConsolePayload = Readonly<{\n consoleArgs: readonly string[];\n consoleLogMessage: string;\n consoleStackTrace: string;\n}>;\n\ntype StringifiablePrimitive = bigint | boolean | number | string | symbol;\n\ntype StringifiedArgument = Readonly<{\n /**\n * The JSON-safe value behind an object's `text`. The log file writes it as\n * compact JSON; it is only serialized again when a file is written.\n */\n jsonValue?: unknown;\n kind: StringifiedArgumentKind;\n text: string;\n}>;\n\ntype StringifiedArgumentKind =\n | \"boolean\"\n | \"function\"\n | \"nullish\"\n | \"number\"\n | \"object\"\n | \"string\"\n | \"symbol\";\n\nconst LOG_LEVEL_COLORS: Readonly<Record<LogLevel, number>> = {\n DEBUG: ANSI_CYAN,\n ERROR: ANSI_RED,\n INFO: ANSI_GREEN,\n WARN: ANSI_YELLOW\n};\n\nfunction colorize(text: string, colorCode: number): string {\n return `\\u001B[${colorCode}m${text}\\u001B[${ANSI_RESET_COLOR}m`;\n}\n\nfunction isPrimitiveArgument(\n argument: unknown\n): argument is StringifiablePrimitive {\n return (\n typeof argument === \"bigint\" ||\n typeof argument === \"boolean\" ||\n typeof argument === \"number\" ||\n typeof argument === \"string\" ||\n typeof argument === \"symbol\"\n );\n}\n\nfunction stringifyPrimitiveArgument(\n argument: StringifiablePrimitive\n): StringifiedArgument {\n if (typeof argument === \"string\") {\n return {\n kind: \"string\",\n text: argument\n };\n }\n\n if (typeof argument === \"symbol\") {\n return {\n kind: \"symbol\",\n text: argument.toString()\n };\n }\n\n if (typeof argument === \"boolean\") {\n return {\n kind: \"boolean\",\n text: `${argument}`\n };\n }\n\n return {\n kind: \"number\",\n text: `${argument}`\n };\n}\n\nfunction stringifyFunctionArgument(functionName: string): StringifiedArgument {\n return {\n kind: \"function\",\n text: formatFunctionLabel(functionName)\n };\n}\n\nfunction stringifyJsonArgument(argument: unknown): StringifiedArgument {\n try {\n const safeValue = toJsonSafeValue(argument);\n const stringifiedArgument = JSON.stringify(\n safeValue,\n undefined,\n JSON_INDENTATION\n );\n\n if (typeof stringifiedArgument !== \"string\") {\n return {\n kind: \"object\",\n text: FALLBACK_OBJECT_STRING\n };\n }\n\n return {\n jsonValue: safeValue,\n kind: \"object\",\n text: stringifiedArgument\n };\n } catch {\n return {\n kind: \"object\",\n text: FALLBACK_OBJECT_STRING\n };\n }\n}\n\nfunction stringifyArgument(argument: unknown): StringifiedArgument {\n if (typeof argument === \"undefined\") {\n return {\n kind: \"nullish\",\n text: \"undefined\"\n };\n }\n\n if (argument === null) {\n return {\n kind: \"nullish\",\n text: \"null\"\n };\n }\n\n if (isPrimitiveArgument(argument)) {\n return stringifyPrimitiveArgument(argument);\n }\n\n if (typeof argument === \"function\") {\n return stringifyFunctionArgument(argument.name);\n }\n\n return stringifyJsonArgument(argument);\n}\n\nfunction stringifyArguments(\n argumentsList: readonly unknown[]\n): readonly StringifiedArgument[] {\n return argumentsList.map((argument) => {\n return stringifyArgument(argument);\n });\n}\n\nfunction buildColoredLogMessage(\n level: LogLevel,\n timestamp: string,\n loggerName: string,\n openTelemetryContextLabel: string,\n message: string\n): string {\n const colorCode = LOG_LEVEL_COLORS[level];\n\n return buildLogMessage(\n colorize(timestamp, colorCode),\n colorize(`[${level}]`, colorCode),\n colorize(loggerName, colorCode),\n openTelemetryContextLabel,\n colorize(message, colorCode)\n );\n}\n\nfunction colorizeOpenTelemetryContextLabel(\n level: LogLevel,\n openTelemetryContext: OpenTelemetryContext | undefined,\n valueColorMode: ValueColorMode\n): string {\n const plainOpenTelemetryContextLabel =\n formatOpenTelemetryContextLabel(openTelemetryContext);\n\n if (\n valueColorMode === \"off\" ||\n plainOpenTelemetryContextLabel.length === EMPTY_LENGTH\n ) {\n return plainOpenTelemetryContextLabel;\n }\n\n if (valueColorMode === \"syntax\") {\n return colorize(plainOpenTelemetryContextLabel, ANSI_GRAY);\n }\n\n return colorize(plainOpenTelemetryContextLabel, LOG_LEVEL_COLORS[level]);\n}\n\nfunction getSyntaxColorCode(kind: StringifiedArgumentKind): number {\n switch (kind) {\n case \"boolean\": {\n return ANSI_YELLOW;\n }\n case \"function\": {\n return ANSI_MAGENTA;\n }\n case \"nullish\": {\n return ANSI_GRAY;\n }\n case \"number\": {\n return ANSI_CYAN;\n }\n case \"object\": {\n return ANSI_BLUE;\n }\n case \"string\": {\n return ANSI_GREEN;\n }\n case \"symbol\": {\n return ANSI_MAGENTA;\n }\n default: {\n return ANSI_GREEN;\n }\n }\n}\n\nfunction colorizeArguments(\n argumentsList: readonly StringifiedArgument[],\n level: LogLevel,\n valueColorMode: ValueColorMode\n): readonly string[] {\n if (valueColorMode === \"off\") {\n return argumentsList.map((argument) => {\n return argument.text;\n });\n }\n\n if (valueColorMode === \"syntax\") {\n return argumentsList.map((argument) => {\n return colorize(argument.text, getSyntaxColorCode(argument.kind));\n });\n }\n\n const colorCode = LOG_LEVEL_COLORS[level];\n\n return argumentsList.map((argument) => {\n return colorize(argument.text, colorCode);\n });\n}\n\nfunction buildPlainConsoleLogMessage(\n level: LogLevel,\n timestamp: string,\n loggerName: string,\n openTelemetryContext: OpenTelemetryContext | undefined,\n message: string\n): string {\n return buildLogMessage(\n timestamp,\n `[${level}]`,\n loggerName,\n formatOpenTelemetryContextLabel(openTelemetryContext),\n message\n );\n}\n\nfunction buildConsoleLogMessage(\n level: LogLevel,\n timestamp: string,\n loggerName: string,\n openTelemetryContext: OpenTelemetryContext | undefined,\n message: string,\n valueColorMode: ValueColorMode\n): string {\n if (valueColorMode === \"off\") {\n return buildPlainConsoleLogMessage(\n level,\n timestamp,\n loggerName,\n openTelemetryContext,\n message\n );\n }\n\n return buildColoredLogMessage(\n level,\n timestamp,\n loggerName,\n colorizeOpenTelemetryContextLabel(\n level,\n openTelemetryContext,\n valueColorMode\n ),\n message\n );\n}\n\nfunction buildConsoleStackTrace(\n stackTrace: string,\n level: LogLevel,\n valueColorMode: ValueColorMode\n): string {\n if (valueColorMode === \"off\") {\n return stackTrace;\n }\n\n return colorize(stackTrace, LOG_LEVEL_COLORS[level]);\n}\n\nfunction createConsolePayload(\n entry: LogEntry,\n args: readonly StringifiedArgument[],\n output: LogOutput\n): ConsolePayload {\n const { level } = entry;\n const { valueColorMode } = output;\n\n return {\n consoleArgs: colorizeArguments(args, level, valueColorMode),\n consoleLogMessage: buildConsoleLogMessage(\n level,\n formatConsoleTimestamp(\n entry.epochMilliseconds,\n output.timestampFormat\n ),\n entry.loggerName,\n entry.openTelemetryContext,\n entry.message,\n valueColorMode\n ),\n consoleStackTrace: buildConsoleStackTrace(\n entry.stackTrace,\n level,\n valueColorMode\n )\n };\n}\n\n/**\n * The writer for terminals and server logs: every argument is turned into text\n * (objects as JSON, with the safety rules of `toJsonSafeValue`), colored with\n * ANSI codes unless `valueColorMode` is `\"off\"`.\n *\n * @param {LoggerConsole} loggerConsole - Where console output goes.\n * @param {LogFileWriter} [writeLogFile] - Writes the log file; only runtimes\n * that can write files pass one.\n * @returns {LogWriter} The runtime's `write`.\n */\nfunction createTextLogWriter(\n loggerConsole: LoggerConsole,\n writeLogFile?: LogFileWriter\n): LogWriter {\n return (entry, output) => {\n const args = stringifyArguments(entry.args);\n\n if (output.writeToFile && typeof writeLogFile === \"function\") {\n writeLogFile(output.logFilePath, { ...entry, args });\n }\n\n const payload = createConsolePayload(entry, args, output);\n\n loggerConsole.log(payload.consoleLogMessage, ...payload.consoleArgs);\n if (entry.stackTrace.length > EMPTY_LENGTH) {\n loggerConsole.error(payload.consoleStackTrace);\n }\n };\n}\n\nexport { createTextLogWriter };\nexport type { StringifiedArgument };\n"],"mappings":";;;;AAiBA,MAAM,mBAAmB;AACzB,MAAM,aAAa;AACnB,MAAM,cAAc;AACpB,MAAM,WAAW;AACjB,MAAM,YAAY;AAClB,MAAM,YAAY;AAClB,MAAM,eAAe;AACrB,MAAM,YAAY;AAClB,MAAM,eAAe;AACrB,MAAM,mBAAmB;AACzB,MAAM,yBAAyB;AA6B/B,MAAM,mBAAuD;CACzD,OAAO;CACP,OAAO;CACP,MAAM;CACN,MAAM;AACV;AAEA,SAAS,SAAS,MAAc,WAA2B;CACvD,OAAO,UAAU,UAAU,GAAG,KAAK,SAAS,iBAAiB;AACjE;AAEA,SAAS,oBACL,UACkC;CAClC,OACI,OAAO,aAAa,YACpB,OAAO,aAAa,aACpB,OAAO,aAAa,YACpB,OAAO,aAAa,YACpB,OAAO,aAAa;AAE5B;AAEA,SAAS,2BACL,UACmB;CACnB,IAAI,OAAO,aAAa,UACpB,OAAO;EACH,MAAM;EACN,MAAM;CACV;CAGJ,IAAI,OAAO,aAAa,UACpB,OAAO;EACH,MAAM;EACN,MAAM,SAAS,SAAS;CAC5B;CAGJ,IAAI,OAAO,aAAa,WACpB,OAAO;EACH,MAAM;EACN,MAAM,GAAG;CACb;CAGJ,OAAO;EACH,MAAM;EACN,MAAM,GAAG;CACb;AACJ;AAEA,SAAS,0BAA0B,cAA2C;CAC1E,OAAO;EACH,MAAM;EACN,MAAM,oBAAoB,YAAY;CAC1C;AACJ;AAEA,SAAS,sBAAsB,UAAwC;CACnE,IAAI;EACA,MAAM,YAAY,gBAAgB,QAAQ;EAC1C,MAAM,sBAAsB,KAAK,UAC7B,WACA,KAAA,GACA,gBACJ;EAEA,IAAI,OAAO,wBAAwB,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,CAAC;EAGvD,MAAM,UAAU,qBAAqB,OAAO,MAAM,MAAM;EAExD,cAAc,IAAI,QAAQ,mBAAmB,GAAG,QAAQ,WAAW;EACnE,IAAI,MAAM,WAAW,SAAS,cAC1B,cAAc,MAAM,QAAQ,iBAAiB;CAErD;AACJ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"console_timestamp.js","names":[],"sources":["../src/console_timestamp.ts"],"sourcesContent":["/** `\"iso\"`: `2026-11-19T16:59:23.745Z`; `\"time\"`: local `16:59:23.745`. */\ntype TimestampFormat = \"iso\" | \"time\";\n\nconst TIME_PART_WIDTH = 2;\nconst MILLISECONDS_WIDTH = 3;\n\nfunction padTimePart(value: number, width = TIME_PART_WIDTH): string {\n return `${value}`.padStart(width, \"0\");\n}\n\n/**\n * `\"time\"` is the local time of day, the clock a developer reads the log\n * against.\n *\n * @param {number} epochMilliseconds - The moment of the log call.\n * @param {TimestampFormat} format - The console timestamp format.\n * @returns {string} `16:59:23.745` for `\"time\"`, the ISO string for `\"iso\"`.\n */\nfunction formatConsoleTimestamp(\n epochMilliseconds: number,\n format: TimestampFormat
|
|
1
|
+
{"version":3,"file":"console_timestamp.js","names":[],"sources":["../src/console_timestamp.ts"],"sourcesContent":["/** `\"iso\"`: `2026-11-19T16:59:23.745Z`; `\"time\"`: local `16:59:23.745`. */\ntype TimestampFormat = \"iso\" | \"time\";\n\nconst TIME_PART_WIDTH = 2;\nconst MILLISECONDS_WIDTH = 3;\n\nfunction padTimePart(value: number, width = TIME_PART_WIDTH): string {\n return `${value}`.padStart(width, \"0\");\n}\n\n/**\n * `\"time\"` is the local time of day, the clock a developer reads the log\n * against.\n *\n * @param {number} epochMilliseconds - The moment of the log call.\n * @param {TimestampFormat} format - The console timestamp format.\n * @returns {string} `16:59:23.745` for `\"time\"`, the ISO string for `\"iso\"`.\n */\nfunction formatConsoleTimestamp(\n epochMilliseconds: number,\n format: TimestampFormat\n): string {\n const date = new Date(epochMilliseconds);\n\n if (format === \"iso\") {\n return date.toISOString();\n }\n\n return `${padTimePart(date.getHours())}:${padTimePart(date.getMinutes())}:${padTimePart(date.getSeconds())}.${padTimePart(date.getMilliseconds(), MILLISECONDS_WIDTH)}`;\n}\n\nexport { formatConsoleTimestamp };\nexport type { TimestampFormat };\n"],"mappings":";AAGA,MAAM,kBAAkB;AACxB,MAAM,qBAAqB;AAE3B,SAAS,YAAY,OAAe,QAAQ,iBAAyB;CACjE,OAAO,GAAG,QAAQ,SAAS,OAAO,GAAG;AACzC;;;;;;;;;AAUA,SAAS,uBACL,mBACA,QACM;CACN,MAAM,OAAO,IAAI,KAAK,iBAAiB;CAEvC,IAAI,WAAW,OACX,OAAO,KAAK,YAAY;CAG5B,OAAO,GAAG,YAAY,KAAK,SAAS,CAAC,EAAE,GAAG,YAAY,KAAK,WAAW,CAAC,EAAE,GAAG,YAAY,KAAK,WAAW,CAAC,EAAE,GAAG,YAAY,KAAK,gBAAgB,GAAG,kBAAkB;AACxK"}
|
|
@@ -25,8 +25,8 @@ type RequestLoggerNameResolver = (context: RequestLoggerContext) => string;
|
|
|
25
25
|
type HonoLoggerMiddlewareOptions = Readonly<{
|
|
26
26
|
/**
|
|
27
27
|
* Adds the request's query string (`?a=1&b=2`) to the logged metadata as
|
|
28
|
-
* `query`. Off by default: query strings often carry tokens, OAuth codes
|
|
29
|
-
* e-mail addresses, and the log keeps only the path.
|
|
28
|
+
* `query`. Off by default: query strings often carry tokens, OAuth codes
|
|
29
|
+
* and e-mail addresses, and the log keeps only the path.
|
|
30
30
|
*/
|
|
31
31
|
includeQuery?: boolean;
|
|
32
32
|
logCompletedRequests?: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hono_middleware.js","names":[],"sources":["../src/hono_middleware.ts"],"sourcesContent":["import type { MiddlewareHandler } from \"hono\";\nimport { getRuntimeKey } from \"hono/adapter\";\nimport { createMiddleware } from \"hono/factory\";\n\nimport type { LoggerBase } from \"./logger_factory\";\n\nconst DEFAULT_ERROR_STATUS = 500;\nconst DEFAULT_REQUEST_LOGGER_NAME = \"request\";\nconst EMPTY_REQUEST_ID = \"\";\nconst FAILED_REQUEST_MESSAGE = \"Request failed\";\nconst REQUEST_COMPLETED_MESSAGE = \"Request completed\";\nconst REQUEST_ID_HEADER = \"x-request-id\";\nconst EMPTY_QUERY = \"\";\n\ntype RequestRuntimeKey = ReturnType<typeof getRuntimeKey>;\n\ntype HonoLoggerVariables = {\n logger: LoggerBase;\n};\n\ntype HonoLoggerMiddleware = MiddlewareHandler<{\n Variables: HonoLoggerVariables;\n}>;\n\ntype RequestLike = Readonly<{\n header: (name: string) => string | undefined;\n method: string;\n path: string;\n url: string;\n}>;\n\ntype ResponseLike = Readonly<{\n status: number;\n}>;\n\ntype RequestOnlyReader = Readonly<{\n req: RequestLike;\n}>;\n\ntype RequestContextReader = Readonly<{\n error?: unknown;\n req: RequestLike;\n res: ResponseLike;\n}>;\n\ntype MiddlewareContext = Readonly<{\n error?: unknown;\n req: RequestLike;\n res: ResponseLike;\n set: (key: \"logger\", value: Readonly<LoggerBase>) => void;\n}>;\n\ntype MiddlewareParameters = readonly [MiddlewareContext, () => Promise<void>];\n\ntype RequestMetadataValue = number | string;\n\ntype RequestLoggerContext = Readonly<{\n method: string;\n path: string;\n /**\n * The query string including the leading `?` (`\"?a=1&b=2\"`), or `\"\"` when\n * there is none. It is passed to `requestLoggerName` only; the middleware\n * logs it as `query` just when `includeQuery` is on.\n */\n query: string;\n requestId: string;\n runtime: RequestRuntimeKey;\n url: string;\n}>;\n\ntype RequestLoggerNameResolver = (context: RequestLoggerContext) => string;\n\ntype HonoLoggerMiddlewareOptions = Readonly<{\n /**\n * Adds the request's query string (`?a=1&b=2`) to the logged metadata as\n * `query`. Off by default: query strings often carry tokens, OAuth codes and\n * e-mail addresses, and the log keeps only the path.\n */\n includeQuery?: boolean;\n logCompletedRequests?: boolean;\n logger: Readonly<LoggerBase>;\n requestLoggerName?: RequestLoggerNameResolver | string;\n}>;\n\ntype RequestLoggingState = Readonly<{\n requestLogger: Readonly<LoggerBase>;\n requestLoggerContext: RequestLoggerContext;\n startTime: number;\n}>;\n\nfunction resolveRequestId(c: RequestOnlyReader): string {\n const requestId = c.req.header(REQUEST_ID_HEADER);\n\n if (\n typeof requestId !== \"string\" ||\n requestId.length === EMPTY_REQUEST_ID.length\n ) {\n return EMPTY_REQUEST_ID;\n }\n\n return requestId;\n}\n\nfunction extractQuery(url: string): string {\n try {\n return new URL(url).search;\n } catch {\n // Hono hands out absolute URLs; anything else has no query we can trust.\n return EMPTY_QUERY;\n }\n}\n\nfunction createRequestLoggerContext(\n c: RequestOnlyReader,\n): RequestLoggerContext {\n return {\n method: c.req.method,\n path: c.req.path,\n query: extractQuery(c.req.url),\n requestId: resolveRequestId(c),\n runtime: getRuntimeKey(),\n url: c.req.url,\n };\n}\n\nfunction resolveRequestLoggerName(\n requestLoggerContext: RequestLoggerContext,\n requestLoggerName: HonoLoggerMiddlewareOptions[\"requestLoggerName\"],\n): string {\n if (typeof requestLoggerName === \"function\") {\n return requestLoggerName(requestLoggerContext);\n }\n\n if (typeof requestLoggerName === \"string\") {\n return requestLoggerName;\n }\n\n return DEFAULT_REQUEST_LOGGER_NAME;\n}\n\nfunction createRequestLogger(\n logger: Readonly<LoggerBase>,\n requestLoggerContext: RequestLoggerContext,\n requestLoggerName: HonoLoggerMiddlewareOptions[\"requestLoggerName\"],\n): Readonly<LoggerBase> {\n return logger.createChildLogger(\n resolveRequestLoggerName(requestLoggerContext, requestLoggerName),\n );\n}\n\nfunction createRequestOnlyReader(c: MiddlewareContext): RequestOnlyReader {\n return {\n req: {\n header(name: string): string | undefined {\n return c.req.header(name);\n },\n method: c.req.method,\n path: c.req.path,\n url: c.req.url,\n },\n };\n}\n\n/**\n * Reads the response status, so call it only after `next()`. Hono's `c.res`\n * getter creates a placeholder Response on first access, and a handler's own\n * Response is then copied into a new one (`new Response(body, res)`) when it is\n * set. Touching `c.res` before the handler ran therefore replaces every\n * response and loses its identity.\n *\n * @param {MiddlewareContext} c - The Hono context, after `next()` returned.\n * @returns {RequestContextReader} The request, the error and the status.\n */\nfunction createRequestReader(c: MiddlewareContext): RequestContextReader {\n return {\n ...createRequestOnlyReader(c),\n error: c.error,\n res: {\n status: c.res.status,\n },\n };\n}\n\nfunction createRequestLoggingState(\n c: MiddlewareContext,\n options: HonoLoggerMiddlewareOptions,\n): RequestLoggingState {\n const requestLoggerContext = createRequestLoggerContext(\n createRequestOnlyReader(c),\n );\n\n return {\n requestLogger: createRequestLogger(\n options.logger,\n requestLoggerContext,\n options.requestLoggerName,\n ),\n requestLoggerContext,\n startTime: Date.now(),\n };\n}\n\nfunction buildRequestMetadata(\n requestLoggerContext: RequestLoggerContext,\n includeQuery: boolean,\n durationMs: number,\n status: number,\n): Readonly<Record<string, RequestMetadataValue>> {\n const requestMetadata: Record<string, RequestMetadataValue> = {\n durationMs,\n method: requestLoggerContext.method,\n path: requestLoggerContext.path,\n runtime: requestLoggerContext.runtime,\n status,\n };\n\n if (\n includeQuery &&\n requestLoggerContext.query.length > EMPTY_QUERY.length\n ) {\n requestMetadata.query = requestLoggerContext.query;\n }\n\n if (requestLoggerContext.requestId.length > EMPTY_REQUEST_ID.length) {\n requestMetadata.requestId = requestLoggerContext.requestId;\n }\n\n return requestMetadata;\n}\n\nfunction serializeThrownError(\n error: unknown,\n): Readonly<Record<string, string>> {\n if (error instanceof Error) {\n return {\n message: error.message,\n name: error.name,\n stack: error.stack ?? \"\",\n };\n }\n\n return {\n message: String(error),\n name: \"UnknownError\",\n stack: \"\",\n };\n}\n\nfunction getElapsedMilliseconds(startTime: number): number {\n return Date.now() - startTime;\n}\n\nfunction shouldLogCompletedRequests(\n logCompletedRequests: boolean | undefined,\n): boolean {\n return logCompletedRequests ?? true;\n}\n\nfunction shouldIncludeQuery(includeQuery: boolean | undefined): boolean {\n return includeQuery ?? false;\n}\n\nfunction logCompletedRequest(\n c: RequestContextReader,\n requestLogger: Readonly<LoggerBase>,\n requestLoggerContext: RequestLoggerContext,\n includeQuery: boolean,\n startTime: number,\n): void {\n requestLogger.info(\n REQUEST_COMPLETED_MESSAGE,\n buildRequestMetadata(\n requestLoggerContext,\n includeQuery,\n getElapsedMilliseconds(startTime),\n c.res.status,\n ),\n );\n}\n\nfunction logFailedRequest(\n c: RequestContextReader,\n requestLogger: Readonly<LoggerBase>,\n requestLoggerContext: RequestLoggerContext,\n includeQuery: boolean,\n startTime: number,\n): void {\n requestLogger.error(\n FAILED_REQUEST_MESSAGE,\n buildRequestMetadata(\n requestLoggerContext,\n includeQuery,\n getElapsedMilliseconds(startTime),\n c.res.status || DEFAULT_ERROR_STATUS,\n ),\n serializeThrownError(c.error),\n );\n}\n\nfunction finalizeRequestLogging(\n c: MiddlewareContext,\n options: HonoLoggerMiddlewareOptions,\n requestLoggingState: RequestLoggingState,\n): void {\n const requestReader = createRequestReader(c);\n const includeQuery = shouldIncludeQuery(options.includeQuery);\n\n if (typeof requestReader.error !== \"undefined\") {\n logFailedRequest(\n requestReader,\n requestLoggingState.requestLogger,\n requestLoggingState.requestLoggerContext,\n includeQuery,\n requestLoggingState.startTime,\n );\n return;\n }\n\n if (!shouldLogCompletedRequests(options.logCompletedRequests)) {\n return;\n }\n\n logCompletedRequest(\n requestReader,\n requestLoggingState.requestLogger,\n requestLoggingState.requestLoggerContext,\n includeQuery,\n requestLoggingState.startTime,\n );\n}\n\nfunction createHonoLoggerMiddleware(\n options: HonoLoggerMiddlewareOptions,\n): HonoLoggerMiddleware {\n return createMiddleware<{\n Variables: HonoLoggerVariables;\n }>(async (...[c, next]: MiddlewareParameters): Promise<void> => {\n const requestLoggingState = createRequestLoggingState(c, options);\n\n c.set(\"logger\", requestLoggingState.requestLogger);\n await next();\n finalizeRequestLogging(c, options, requestLoggingState);\n });\n}\n\nexport { createHonoLoggerMiddleware };\n\nexport type {\n HonoLoggerMiddlewareOptions,\n HonoLoggerVariables,\n RequestLoggerContext,\n};\n"],"mappings":";;;AAMA,MAA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a;EAC5C,iBACI,eACA,oBAAoB,eACpB,oBAAoB,sBACpB,cACA,oBAAoB,SACxB;EACA;CACJ;CAEA,IAAI,CAAC,2BAA2B,QAAQ,oBAAoB,GACxD;CAGJ,oBACI,eACA,oBAAoB,eACpB,oBAAoB,sBACpB,cACA,oBAAoB,SACxB;AACJ;AAEA,SAAS,2BACL,SACoB;CACpB,OAAO,iBAEJ,OAAO,GAAG,CAAC,GAAG,UAA+C;EAC5D,MAAM,sBAAsB,0BAA0B,GAAG,OAAO;EAEhE,EAAE,IAAI,UAAU,oBAAoB,aAAa;EACjD,MAAM,KAAK;EACX,uBAAuB,GAAG,SAAS,mBAAmB;CAC1D,CAAC;AACL"}
|
|
1
|
+
{"version":3,"file":"hono_middleware.js","names":[],"sources":["../src/hono_middleware.ts"],"sourcesContent":["import type { MiddlewareHandler } from \"hono\";\nimport { getRuntimeKey } from \"hono/adapter\";\nimport { createMiddleware } from \"hono/factory\";\n\nimport type { LoggerBase } from \"./logger_factory\";\n\nconst DEFAULT_ERROR_STATUS = 500;\nconst DEFAULT_REQUEST_LOGGER_NAME = \"request\";\nconst EMPTY_REQUEST_ID = \"\";\nconst FAILED_REQUEST_MESSAGE = \"Request failed\";\nconst REQUEST_COMPLETED_MESSAGE = \"Request completed\";\nconst REQUEST_ID_HEADER = \"x-request-id\";\nconst EMPTY_QUERY = \"\";\n\ntype RequestRuntimeKey = ReturnType<typeof getRuntimeKey>;\n\ntype HonoLoggerVariables = {\n logger: LoggerBase;\n};\n\ntype HonoLoggerMiddleware = MiddlewareHandler<{\n Variables: HonoLoggerVariables;\n}>;\n\ntype RequestLike = Readonly<{\n header: (name: string) => string | undefined;\n method: string;\n path: string;\n url: string;\n}>;\n\ntype ResponseLike = Readonly<{\n status: number;\n}>;\n\ntype RequestOnlyReader = Readonly<{\n req: RequestLike;\n}>;\n\ntype RequestContextReader = Readonly<{\n error?: unknown;\n req: RequestLike;\n res: ResponseLike;\n}>;\n\ntype MiddlewareContext = Readonly<{\n error?: unknown;\n req: RequestLike;\n res: ResponseLike;\n set: (key: \"logger\", value: Readonly<LoggerBase>) => void;\n}>;\n\ntype MiddlewareParameters = readonly [MiddlewareContext, () => Promise<void>];\n\ntype RequestMetadataValue = number | string;\n\ntype RequestLoggerContext = Readonly<{\n method: string;\n path: string;\n /**\n * The query string including the leading `?` (`\"?a=1&b=2\"`), or `\"\"` when\n * there is none. It is passed to `requestLoggerName` only; the middleware\n * logs it as `query` just when `includeQuery` is on.\n */\n query: string;\n requestId: string;\n runtime: RequestRuntimeKey;\n url: string;\n}>;\n\ntype RequestLoggerNameResolver = (context: RequestLoggerContext) => string;\n\ntype HonoLoggerMiddlewareOptions = Readonly<{\n /**\n * Adds the request's query string (`?a=1&b=2`) to the logged metadata as\n * `query`. Off by default: query strings often carry tokens, OAuth codes\n * and e-mail addresses, and the log keeps only the path.\n */\n includeQuery?: boolean;\n logCompletedRequests?: boolean;\n logger: Readonly<LoggerBase>;\n requestLoggerName?: RequestLoggerNameResolver | string;\n}>;\n\ntype RequestLoggingState = Readonly<{\n requestLogger: Readonly<LoggerBase>;\n requestLoggerContext: RequestLoggerContext;\n startTime: number;\n}>;\n\nfunction resolveRequestId(c: RequestOnlyReader): string {\n const requestId = c.req.header(REQUEST_ID_HEADER);\n\n if (\n typeof requestId !== \"string\" ||\n requestId.length === EMPTY_REQUEST_ID.length\n ) {\n return EMPTY_REQUEST_ID;\n }\n\n return requestId;\n}\n\nfunction extractQuery(url: string): string {\n try {\n return new URL(url).search;\n } catch {\n // Hono hands out absolute URLs; anything else has no query we can trust.\n return EMPTY_QUERY;\n }\n}\n\nfunction createRequestLoggerContext(\n c: RequestOnlyReader\n): RequestLoggerContext {\n return {\n method: c.req.method,\n path: c.req.path,\n query: extractQuery(c.req.url),\n requestId: resolveRequestId(c),\n runtime: getRuntimeKey(),\n url: c.req.url\n };\n}\n\nfunction resolveRequestLoggerName(\n requestLoggerContext: RequestLoggerContext,\n requestLoggerName: HonoLoggerMiddlewareOptions[\"requestLoggerName\"]\n): string {\n if (typeof requestLoggerName === \"function\") {\n return requestLoggerName(requestLoggerContext);\n }\n\n if (typeof requestLoggerName === \"string\") {\n return requestLoggerName;\n }\n\n return DEFAULT_REQUEST_LOGGER_NAME;\n}\n\nfunction createRequestLogger(\n logger: Readonly<LoggerBase>,\n requestLoggerContext: RequestLoggerContext,\n requestLoggerName: HonoLoggerMiddlewareOptions[\"requestLoggerName\"]\n): Readonly<LoggerBase> {\n return logger.createChildLogger(\n resolveRequestLoggerName(requestLoggerContext, requestLoggerName)\n );\n}\n\nfunction createRequestOnlyReader(c: MiddlewareContext): RequestOnlyReader {\n return {\n req: {\n header(name: string): string | undefined {\n return c.req.header(name);\n },\n method: c.req.method,\n path: c.req.path,\n url: c.req.url\n }\n };\n}\n\n/**\n * Reads the response status, so call it only after `next()`. Hono's `c.res`\n * getter creates a placeholder Response on first access, and a handler's own\n * Response is then copied into a new one (`new Response(body, res)`) when it is\n * set. Touching `c.res` before the handler ran therefore replaces every\n * response and loses its identity.\n *\n * @param {MiddlewareContext} c - The Hono context, after `next()` returned.\n * @returns {RequestContextReader} The request, the error and the status.\n */\nfunction createRequestReader(c: MiddlewareContext): RequestContextReader {\n return {\n ...createRequestOnlyReader(c),\n error: c.error,\n res: {\n status: c.res.status\n }\n };\n}\n\nfunction createRequestLoggingState(\n c: MiddlewareContext,\n options: HonoLoggerMiddlewareOptions\n): RequestLoggingState {\n const requestLoggerContext = createRequestLoggerContext(\n createRequestOnlyReader(c)\n );\n\n return {\n requestLogger: createRequestLogger(\n options.logger,\n requestLoggerContext,\n options.requestLoggerName\n ),\n requestLoggerContext,\n startTime: Date.now()\n };\n}\n\nfunction buildRequestMetadata(\n requestLoggerContext: RequestLoggerContext,\n includeQuery: boolean,\n durationMs: number,\n status: number\n): Readonly<Record<string, RequestMetadataValue>> {\n const requestMetadata: Record<string, RequestMetadataValue> = {\n durationMs,\n method: requestLoggerContext.method,\n path: requestLoggerContext.path,\n runtime: requestLoggerContext.runtime,\n status\n };\n\n if (\n includeQuery &&\n requestLoggerContext.query.length > EMPTY_QUERY.length\n ) {\n requestMetadata.query = requestLoggerContext.query;\n }\n\n if (requestLoggerContext.requestId.length > EMPTY_REQUEST_ID.length) {\n requestMetadata.requestId = requestLoggerContext.requestId;\n }\n\n return requestMetadata;\n}\n\nfunction serializeThrownError(\n error: unknown\n): Readonly<Record<string, string>> {\n if (error instanceof Error) {\n return {\n message: error.message,\n name: error.name,\n stack: error.stack ?? \"\"\n };\n }\n\n return {\n message: String(error),\n name: \"UnknownError\",\n stack: \"\"\n };\n}\n\nfunction getElapsedMilliseconds(startTime: number): number {\n return Date.now() - startTime;\n}\n\nfunction shouldLogCompletedRequests(\n logCompletedRequests: boolean | undefined\n): boolean {\n return logCompletedRequests ?? true;\n}\n\nfunction shouldIncludeQuery(includeQuery: boolean | undefined): boolean {\n return includeQuery ?? false;\n}\n\nfunction logCompletedRequest(\n c: RequestContextReader,\n requestLogger: Readonly<LoggerBase>,\n requestLoggerContext: RequestLoggerContext,\n includeQuery: boolean,\n startTime: number\n): void {\n requestLogger.info(\n REQUEST_COMPLETED_MESSAGE,\n buildRequestMetadata(\n requestLoggerContext,\n includeQuery,\n getElapsedMilliseconds(startTime),\n c.res.status\n )\n );\n}\n\nfunction logFailedRequest(\n c: RequestContextReader,\n requestLogger: Readonly<LoggerBase>,\n requestLoggerContext: RequestLoggerContext,\n includeQuery: boolean,\n startTime: number\n): void {\n requestLogger.error(\n FAILED_REQUEST_MESSAGE,\n buildRequestMetadata(\n requestLoggerContext,\n includeQuery,\n getElapsedMilliseconds(startTime),\n c.res.status || DEFAULT_ERROR_STATUS\n ),\n serializeThrownError(c.error)\n );\n}\n\nfunction finalizeRequestLogging(\n c: MiddlewareContext,\n options: HonoLoggerMiddlewareOptions,\n requestLoggingState: RequestLoggingState\n): void {\n const requestReader = createRequestReader(c);\n const includeQuery = shouldIncludeQuery(options.includeQuery);\n\n if (typeof requestReader.error !== \"undefined\") {\n logFailedRequest(\n requestReader,\n requestLoggingState.requestLogger,\n requestLoggingState.requestLoggerContext,\n includeQuery,\n requestLoggingState.startTime\n );\n return;\n }\n\n if (!shouldLogCompletedRequests(options.logCompletedRequests)) {\n return;\n }\n\n logCompletedRequest(\n requestReader,\n requestLoggingState.requestLogger,\n requestLoggingState.requestLoggerContext,\n includeQuery,\n requestLoggingState.startTime\n );\n}\n\nfunction createHonoLoggerMiddleware(\n options: HonoLoggerMiddlewareOptions\n): HonoLoggerMiddleware {\n return createMiddleware<{\n Variables: HonoLoggerVariables;\n }>(async (...[c, next]: MiddlewareParameters): Promise<void> => {\n const requestLoggingState = createRequestLoggingState(c, options);\n\n c.set(\"logger\", requestLoggingState.requestLogger);\n await next();\n finalizeRequestLogging(c, options, requestLoggingState);\n });\n}\n\nexport { createHonoLoggerMiddleware };\n\nexport type {\n HonoLoggerMiddlewareOptions,\n HonoLoggerVariables,\n RequestLoggerContext\n};\n"],"mappings":";;;AAMA,MAAM,uBAAuB;AAC7B,MAAM,8BAA8B;AACpC,MAAM,mBAAmB;AACzB,MAAM,yBAAyB;AAC/B,MAAM,4BAA4B;AAClC,MAAM,oBAAoB;AAC1B,MAAM,cAAc;AA8EpB,SAAS,iBAAiB,GAA8B;CACpD,MAAM,YAAY,EAAE,IAAI,OAAO,iBAAiB;CAEhD,IACI,OAAO,cAAc,YACrB,UAAU,WAAW,GAErB,OAAO;CAGX,OAAO;AACX;AAEA,SAAS,aAAa,KAAqB;CACvC,IAAI;EACA,OAAO,IAAI,IAAI,GAAG,CAAC,CAAC;CACxB,QAAQ;EAEJ,OAAO;CACX;AACJ;AAEA,SAAS,2BACL,GACoB;CACpB,OAAO;EACH,QAAQ,EAAE,IAAI;EACd,MAAM,EAAE,IAAI;EACZ,OAAO,aAAa,EAAE,IAAI,GAAG;EAC7B,WAAW,iBAAiB,CAAC;EAC7B,SAAS,cAAc;EACvB,KAAK,EAAE,IAAI;CACf;AACJ;AAEA,SAAS,yBACL,sBACA,mBACM;CACN,I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uBAAuB,WAA2B;CACvD,OAAO,KAAK,IAAI,IAAI;AACxB;AAEA,SAAS,2BACL,sBACO;CACP,OAAO,wBAAwB;AACnC;AAEA,SAAS,mBAAmB,cAA4C;CACpE,OAAO,gBAAgB;AAC3B;AAEA,SAAS,oBACL,GACA,eACA,sBACA,cACA,WACI;CACJ,cAAc,KACV,2BACA,qBACI,sBACA,cACA,uBAAuB,SAAS,GAChC,EAAE,IAAI,MACV,CACJ;AACJ;AAEA,SAAS,iBACL,GACA,eACA,sBACA,cACA,WACI;CACJ,cAAc,MACV,wBACA,qBACI,sBACA,cACA,uBAAuB,SAAS,GAChC,EAAE,IAAI,UAAU,oBACpB,GACA,qBAAqB,EAAE,KAAK,CAChC;AACJ;AAEA,SAAS,uBACL,GACA,SACA,qBACI;CACJ,MAAM,gBAAgB,oBAAoB,CAAC;CAC3C,MAAM,eAAe,mBAAmB,QAAQ,YAAY;CAE5D,IAAI,OAAO,cAAc,UAAU,aAAa;EAC5C,iBACI,eACA,oBAAoB,eACpB,oBAAoB,sBACpB,cACA,oBAAoB,SACxB;EACA;CACJ;CAEA,IAAI,CAAC,2BAA2B,QAAQ,oBAAoB,GACxD;CAGJ,oBACI,eACA,oBAAoB,eACpB,oBAAoB,sBACpB,cACA,oBAAoB,SACxB;AACJ;AAEA,SAAS,2BACL,SACoB;CACpB,OAAO,iBAEJ,OAAO,GAAG,CAAC,GAAG,UAA+C;EAC5D,MAAM,sBAAsB,0BAA0B,GAAG,OAAO;EAEhE,EAAE,IAAI,UAAU,oBAAoB,aAAa;EACjD,MAAM,KAAK;EACX,uBAAuB,GAAG,SAAS,mBAAmB;CAC1D,CAAC;AACL"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { StringifiedArgument } from "./console_text.js";
|
|
2
|
+
import { LogEntry } from "./logger_factory.js";
|
|
3
|
+
/** A log entry with its arguments already turned into text. */
|
|
4
|
+
type LogFileEntry = Readonly<Omit<LogEntry, "args"> & {
|
|
5
|
+
args: readonly StringifiedArgument[];
|
|
6
|
+
}>;
|
|
7
|
+
type LogFileWriter = (filePath: string, entry: LogFileEntry) => void;
|
|
8
|
+
export type { LogFileEntry, LogFileWriter };
|
|
9
|
+
//# sourceMappingURL=log_file.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"log_file.d.ts","names":[],"sources":["../src/log_file.ts"],"mappings":";;;KAcK,eAAe,SAChB,KAAK;EACD,eAAe;;KAIlB,iBAAiB,kBAAkB,OAAO"}
|