/** * Logging module for the conductor * * Provides structured logging with configurable levels and optional JSONL tracing. * All conductor logging goes through this module to enable consistent output * formatting and filtering. * * ## Log Levels * * - `error`: Errors that affect operation (component crashes, protocol violations) * - `warn`: Warnings about potential issues (missing responses, malformed messages) * - `info`: Key operational events (component start/stop, connections) * - `debug`: Detailed debugging information (message routing, state changes) * - `trace`: Very detailed tracing (every message, internal state) * * ## Usage * * ```typescript * const logger = createLogger({ level: 'debug', name: 'my-conductor' }); * logger.info('Component started', { component: 'agent', pid: 1234 }); * logger.error('Failed to connect', { error: err.message }); * ``` * * ## JSONL Tracing * * When enabled, all messages routed through the conductor are written to a * JSONL file for debugging and analysis: * * ```typescript * const logger = createLogger({ * level: 'info', * trace: { path: '/tmp/conductor.jsonl' } * }); * ``` */ import type { ConductorMessage } from "./types.js"; import type { JsonRpcMessage } from "@thinkwell/protocol"; /** * Log level enumeration (lower = more severe) */ export type LogLevel = "error" | "warn" | "info" | "debug" | "trace"; /** * Log entry structure for structured logging */ export interface LogEntry { timestamp: string; level: LogLevel; name?: string; message: string; data?: Record; } /** * Trace entry for JSONL message tracing */ export interface TraceEntry { timestamp: string; direction: "left-to-right" | "right-to-left" | "internal"; source?: string; target?: string; message: ConductorMessage | JsonRpcMessage; } /** * Options for JSONL tracing output */ export interface TraceOptions { /** Path to the JSONL trace file */ path: string; } /** * Logger configuration */ export interface LoggerOptions { /** Minimum log level to output (default: 'info') */ level?: LogLevel; /** Optional name prefix for log messages */ name?: string; /** Optional JSONL trace output */ trace?: TraceOptions; /** Use JSON output format instead of human-readable (default: false) */ json?: boolean; } /** * Logger interface */ export interface Logger { /** Log an error message */ error(message: string, data?: Record): void; /** Log a warning message */ warn(message: string, data?: Record): void; /** Log an info message */ info(message: string, data?: Record): void; /** Log a debug message */ debug(message: string, data?: Record): void; /** Log a trace message */ trace(message: string, data?: Record): void; /** Write a trace entry for message inspection */ traceMessage(entry: Omit): void; /** Check if a log level is enabled */ isEnabled(level: LogLevel): boolean; /** Create a child logger with additional context */ child(name: string): Logger; /** Close any open resources (trace file, etc.) */ close(): Promise; } /** * Create a no-op logger that discards all output */ export declare function createNoopLogger(): Logger; /** * Create a logger with the specified options */ export declare function createLogger(options?: LoggerOptions): Logger; /** * Get the default logger */ export declare function getLogger(): Logger; /** * Set the default logger */ export declare function setLogger(logger: Logger): void; //# sourceMappingURL=logger.d.ts.map