UNPKG

@beignet/core

Version:

Core framework primitives for Beignet

72 lines 1.9 kB
/** * Logging hook utilities for @beignet/core/server */ import type { HttpContractConfig } from "../../contracts/index.js"; import { type TrustedRequestInfo } from "../trusted-proxy.js"; import type { HttpRequestLike, HttpResponseHeaders, ServerHook } from "../types.js"; /** * Minimal logger shape accepted by `createLoggingHooks(...)`. */ export interface Logger { /** * Log an informational event. */ info: (...args: unknown[]) => void; /** * Log an error event. */ error: (...args: unknown[]) => void; /** * Log a warning event. */ warn?: (...args: unknown[]) => void; /** * Log a debug event. */ debug?: (...args: unknown[]) => void; } /** * Logging hook configuration. */ export interface LoggingConfig<Ctx> { /** * Logger used when custom lifecycle callbacks are not provided. */ logger?: Logger; /** * Response header name used to expose `ctx.requestId` when present. */ requestIdHeader?: string; /** * Custom request-start observer. */ onRequestStart?: (args: { ctx?: Ctx; req: HttpRequestLike; requestInfo: TrustedRequestInfo; contract?: HttpContractConfig; }) => void; /** * Custom request-end observer. */ onRequestEnd?: (args: { ctx?: Ctx; req: HttpRequestLike; requestInfo: TrustedRequestInfo; res: { status: number; headers: HttpResponseHeaders; }; durationMs: number; contract?: HttpContractConfig; error?: unknown; }) => void; } /** * Create request logging hooks. * * Logging observer errors are intentionally ignored so logging cannot break * request handling. */ export declare function createLoggingHooks<Ctx>(config: LoggingConfig<Ctx>): ServerHook<Ctx>; //# sourceMappingURL=logging.d.ts.map