@steve31415/baselib 3.65.0 → 3.66.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/http.d.ts CHANGED
@@ -1,10 +1,17 @@
1
1
  import type { Hono, Context } from 'hono';
2
2
  import { serve } from '@hono/node-server';
3
3
  import type { Logger } from './log-core.js';
4
+ export interface RequestLoggingOptions {
5
+ /** Extra fields for the exit line, read after the handler (e.g. the hub's
6
+ * `?app=`, so one service's sockets can be told apart by app); fields
7
+ * whose value is undefined are left out. */
8
+ meta?: (c: Context) => Record<string, unknown>;
9
+ }
4
10
  /** One INFO line per request on exit (method, path, status, elapsed,
5
- * identity); /health excluded. Entry-point detail beyond this (key
6
- * parameters, outcomes) is the handler's job per OPERATIONS.md. */
7
- export declare function requestLogging(logger: Logger): import("hono").MiddlewareHandler<any, string, {}, Response>;
11
+ * identity, plus `options.meta`); /health excluded. Entry-point detail
12
+ * beyond this (key parameters, outcomes) is the handler's job per
13
+ * OPERATIONS.md. */
14
+ export declare function requestLogging(logger: Logger, options?: RequestLoggingOptions): import("hono").MiddlewareHandler<any, string, {}, Response>;
8
15
  /** The address of the client that connected to Google's edge, read from
9
16
  * X-Forwarded-For — for per-source rate limits, never for authorization.
10
17
  * Google appends to whatever the client sent, so only the tail can be
package/dist/http.js CHANGED
@@ -7,21 +7,24 @@ import { assertBootSafety } from './config.js';
7
7
  import { flushAllLoggers, logUncaughtErrors } from './log.js';
8
8
  import { truncate } from './log-core.js';
9
9
  /** One INFO line per request on exit (method, path, status, elapsed,
10
- * identity); /health excluded. Entry-point detail beyond this (key
11
- * parameters, outcomes) is the handler's job per OPERATIONS.md. */
12
- export function requestLogging(logger) {
10
+ * identity, plus `options.meta`); /health excluded. Entry-point detail
11
+ * beyond this (key parameters, outcomes) is the handler's job per
12
+ * OPERATIONS.md. */
13
+ export function requestLogging(logger, options = {}) {
13
14
  return createMiddleware(async (c, next) => {
14
15
  if (c.req.path === '/health')
15
16
  return next();
16
17
  const started = Date.now();
17
18
  await next();
18
19
  const identity = c.var.identity;
20
+ const extra = Object.entries(options.meta?.(c) ?? {}).filter(([, value]) => value !== undefined);
19
21
  logger.info(`${c.req.method} ${c.req.path} ${c.res.status}`, {
20
22
  method: c.req.method,
21
23
  path: truncate(c.req.path, 200),
22
24
  status: c.res.status,
23
25
  elapsed_ms: Date.now() - started,
24
26
  ...(identity ? { identity: identity.email } : {}),
27
+ ...Object.fromEntries(extra),
25
28
  });
26
29
  });
27
30
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@steve31415/baselib",
3
- "version": "3.65.0",
3
+ "version": "3.66.0",
4
4
  "description": "Plasticine new-world shared platform library: logging, auth, service-to-service auth, db, HTTP, sync, app updates",
5
5
  "type": "module",
6
6
  "license": "MIT",