/** * Logging Plugin * * Logs all HTTP traffic — method, path, status, duration — like morgan * for Express but for the agentick gateway. Uses the kernel's Logger * for structured, context-aware output. * * ## Limitation * * The gateway's PluginContext does not expose a request-level interceptor * (no `onRequest` hook, no wildcard routes, no HTTP middleware pipeline). * Plugins can only register exact path routes via `ctx.registerRoute()` or * subscribe to lifecycle events via `ctx.on()` — neither of which covers * arbitrary inbound HTTP traffic. * * This plugin therefore exports two things: * * 1. `loggingPlugin()` — A GatewayPlugin that logs gateway lifecycle events * (client connects/disconnects, session creation, plugin registration). * Useful for observability but does NOT log individual HTTP requests. * * 2. `loggingMiddleware()` — A standalone request wrapper for embedded mode. * Wrap `gateway.handleRequest` with this to get morgan-style HTTP logging: * * ```typescript * const mw = loggingMiddleware(); * app.use("/api", (req, res, next) => { * mw(req, res, () => gateway.handleRequest(req, res).catch(next)); * }); * ``` * * When the gateway adds a request interceptor hook to PluginContext, this * plugin should be updated to use it. */ import type { IncomingMessage, ServerResponse } from "node:http"; import { type KernelLogger, type LoggerConfig } from "@agentick/kernel"; import type { GatewayPlugin } from "../types.js"; export interface LoggingPluginConfig { /** Plugin ID (default: "logging") */ id?: string; /** * Pre-configured kernel logger instance. When provided, this is used * directly — giving you full control over level, transport, and format. * * @example * ```typescript * // Custom level + transport * loggingPlugin({ * logger: Logger.create({ * level: 'debug', * transport: { target: 'pino/file', options: { destination: './http.log' } }, * }), * }); * * // Child of global logger with extra bindings * loggingPlugin({ * logger: Logger.child({ service: 'api-gateway' }), * }); * ``` */ logger?: KernelLogger; /** * Logger configuration — creates a standalone logger with these settings. * Ignored when `logger` is provided. When neither `logger` nor * `loggerConfig` is set, falls back to `Logger.for(pluginId)`. * * @example * ```typescript * loggingPlugin({ * loggerConfig: { level: 'debug', prettyPrint: true }, * }); * ``` */ loggerConfig?: LoggerConfig; /** Skip logging for these path prefixes (middleware) or event categories (plugin) */ exclude?: string[]; } /** * Creates a logging middleware that wraps request handling. * Logs method, path, status code, and response time in morgan 'dev' format. * * Uses the kernel Logger for structured output. Configure via `logger` or * `loggerConfig` on the config object. * * @example * ```typescript * // Default — uses Logger.for("HTTP") * const mw = loggingMiddleware(); * * // Custom logger with debug level * const mw = loggingMiddleware({ * logger: Logger.create({ level: 'debug' }), * exclude: ["/health"], * }); * * // In your Express/Fastify/Node handler: * mw(req, res, () => gateway.handleRequest(req, res)); * ``` */ export declare function loggingMiddleware(config?: Pick): (req: IncomingMessage, res: ServerResponse, next: () => void | Promise) => void; /** * Gateway plugin that logs lifecycle events. * * NOTE: This does NOT log individual HTTP requests — the PluginContext lacks * a request interceptor hook. Use `loggingMiddleware()` for HTTP logging. * See module docstring for details. * * @example * ```typescript * // Default — uses Logger.for("logging") * gateway.use(loggingPlugin()); * * // Custom logger with specific transport * gateway.use(loggingPlugin({ * logger: Logger.create({ * level: 'debug', * transport: { target: 'pino-pretty', options: { colorize: true } }, * }), * })); * * // Skip client events * gateway.use(loggingPlugin({ exclude: ["client"] })); * ``` */ export declare function loggingPlugin(config?: LoggingPluginConfig): GatewayPlugin; //# sourceMappingURL=logging.d.ts.map