import type { Server } from 'http'; import { LogLevelName } from '../constants'; interface LogInfo { level: LogLevelName; message: string; timestamp: string; [key: string]: any; } export interface WatchOptions { /** Formatter applied when writing watch lines to disk. Respects user * format choice ('plain' or 'json'). */ format: (info: LogInfo) => string; /** Formatter applied when echoing watch lines to the console. Always * plain+color so live tailing stays readable, regardless of `format`. * Defaults to `format` if not provided (back-compat). */ consoleFormat?: (info: LogInfo) => string; /** When true (set by core when format='json'), watch writes ONE * structured JSON record per request to disk instead of multi-line * emoji banners. The console echo still uses the banner format via * consoleFormat for human readability. */ jsonMode?: boolean; appPrefix: string; watchPrefix: string; fileRotate: boolean; fileFormat: string; fileBackups: number; fileSize: number; use24Hour: boolean; sensitiveFields: string[]; /** Mirror watchman lines to stdout. Default true. */ consoleEnabled?: boolean; /** Cap on captured response body bytes. Default 64 KB. Beyond this, a * placeholder is forwarded; the real total size is always reported via * `WatchEvent.responseBodySize` so the dashboard can show how big the * response was even when we declined to capture it. */ responseBodyMaxBytes?: number; /** Per-request hook so the request/response can be piped into analytics. */ onRequest?: (event: WatchEvent) => void; } export interface WatchEvent { requestId: string; method: string; url: string; statusCode: number; durationMs: number; headers: Record; body?: any; responseBody?: any; /** Parsed query-string params. Sensitive keys are masked. */ query?: Record; /** Express route params (e.g. `:id`). Empty for raw http.Server. */ params?: Record; /** Total response body bytes seen on the wire. Always present (0 if * there was no response body), independent of what was captured. */ responseBodySize?: number; /** "Effective" body for 304 Not Modified responses: the value the route * handler passed to res.json()/res.send() before Express's freshness * check rewrote the response to 304 and cleared the body. Set only * when statusCode is 304 AND we successfully captured the pre-freshness * body via the res.json/res.send hook. The dashboard surfaces this * under a banner so users can see what data the client served from its * cache, mirroring Chrome DevTools' behavior. */ cachedResponseBody?: any; timestamp: number; } export interface WatchHandle { /** Returns an Express-compatible middleware: app.use(logger.middleware()). */ middleware: () => (req: any, res: any, next: any) => void; /** Attach to a specific http.Server instance (plain http, not Express). */ attach: (server: Server) => void; /** Skip recording requests whose path matches `path` exactly or starts * with `path + '/'`. Used by setupDashboard to keep dashboard polling * out of the Requests tab. */ addIgnoredPath: (path: string) => void; } export default function createWatchHandle(options: WatchOptions): WatchHandle; export {};