import { type LevelName } from '../deps/jsr.io/@std/log/0.224.14/levels.js'; import type { LogRecord } from '../deps/jsr.io/@std/log/0.224.14/logger.js'; import { BaseHandler } from '../deps/jsr.io/@std/log/0.224.14/base_handler.js'; import type { CoreContext } from './CoreContext.js'; /** * Base log handler interface for extending Deno standard library handlers. */ export interface LogHandlerBase { handle(logRecord: LogRecord): void; } /** * Configuration options for the {@link ResultsHandler}. */ export interface ResultsHandlerOptions { /** The CoreContext instance to capture results to */ context: CoreContext; /** Formatter function for log messages */ formatter?: (logRecord: LogRecord) => string; } export declare class ResultsHandler extends BaseHandler implements LogHandlerBase { #private; /** The CoreContext instance for capturing results */ context: CoreContext; /** * Creates a new ResultsHandler instance. * * @param levelName - The minimum log level to handle * @param options - Handler configuration including CoreContext * * @example * ```typescript * const context = new CoreContext(contextOptions); * const handler = new ResultsHandler('WARN', { * context, * formatter: '[{levelName}] {msg}' * }); * ``` */ constructor(levelName: LevelName, options: ResultsHandlerOptions); /** * Sets up the handler with event listeners. * * Registers cleanup callbacks for process termination to ensure * proper resource cleanup and result flushing. * * @override */ setup(): void; /** * Handles incoming log records. * * Processes log records through the base handler and triggers * immediate flushing for critical errors above ERROR level. * * @param logRecord - The log record to handle * * @override */ handle(logRecord: LogRecord): void; /** * Captures log messages as results in the context. * * Converts log level names to result types and captures them in the * associated CoreContext at the trail of the subject being generated. * A line logged outside a subject records nothing. * * @param levelName - The log level name ('WARN', 'ERROR' or 'CRITICAL') * * @throws {Error} When an unsupported log level is provided * * @example * ```typescript * // This is called automatically by the logging system * handler.log('WARN'); // Captures as 'warning' result * handler.log('ERROR'); // Captures as 'error' result * handler.log('CRITICAL'); // Captures as 'error' result * ``` */ log(levelName: string): void; /** * Flushes any buffered content. * * This implementation resets the internal buffer. Override * this method in subclasses to implement custom flushing behavior. * * @override */ flush(): void; /** * Destroys the handler and cleans up resources. * * Flushes any remaining content and removes event listeners * to prevent memory leaks. * * @override * * @example * ```typescript * const handler = new ResultsHandler('WARN', { context }); * * try { * // Use handler * logger.addHandler(handler); * await processDocument(); * } finally { * // Always clean up * handler.destroy(); * } * ``` */ destroy(): void; }