/** * Log parser service for terminal log processing. * * Main service that combines ANSI parsing, log level detection, * timestamp extraction, and structured log handling into a * unified API for processing log streams. * * @module components/devenv/terminal/parsing/service */ import type { IParsedLogEntry, IParserState, ILogParserOptions, ILogFilterOptions, ILogStats } from './LogParser.types'; /** * Log parser service class. * * Provides unified API for parsing log text with ANSI colorization, * log level detection, timestamp extraction, and structured data handling. * * @example * ```ts * const parser = new LogParserService(); * const entry = parser.parseLine('2026-02-05T21:35:28.944Z INFO ⦗API⦘ Message'); * // entry.level = 'info' * // entry.timestamp = '2026-02-05T21:35:28.944Z' * // entry.tags = ['API'] * ``` */ export declare class LogParserService { /** ANSI parser instance */ private ansiParser; /** Log level detector instance */ private levelDetector; /** Badge formatter instance */ private badgeFormatter; /** Multiline aggregator instance */ private multilineAggregator; /** Parser options */ private options; /** * Create a new log parser service. * * @param options - Parser configuration options */ constructor(options?: ILogParserOptions); /** * Parse a single log line into structured entry. * * @param line - Raw log line * @param lineNumber - Line number in stream * @param isStderr - Whether this is from stderr * @returns Parsed log entry */ parseLine(line: string, lineNumber: number, isStderr?: boolean): IParsedLogEntry; /** * Parse multiple lines (batch processing). * * @param lines - Array of raw log lines * @param startNumber - Starting line number (default: 1) * @returns Array of parsed log entries */ parseLines(lines: string[], startNumber?: number): IParsedLogEntry[]; /** * Parse logs with incremental state (for streaming). * * Maintains state between chunks for proper multiline log * aggregation and line numbering. Applies multiline aggregation * to mark continuation lines. * * @param chunk - New log chunk * @param prevState - Previous parser state * @returns Parsed entries and new state */ parseIncremental(chunk: string, prevState: IParserState): { entries: IParsedLogEntry[]; newState: IParserState; }; /** * Format log entry for xterm.js display. * * Supports two modes: * * **'raw' mode (default for terminal):** * - Returns the log AS-IS without modifications * - Preserves original ANSI codes from the source (bun, supervisord, etc.) * - No badges, no formatting, just the raw log line * - Prevents ANSI mixing artifacts and visible escape codes * * **'parsed' mode (for React viewer):** * - Strips ANSI codes first * - Adds level badge, tag badges, timestamp badge * - Formats message content for React display * - Continuation lines get indented * * @param entry - Parsed log entry * @param mode - Format mode: 'raw' (default) or 'parsed' * @returns Formatted string for xterm.js or React viewer */ formatForTerminal(entry: IParsedLogEntry, mode?: 'raw' | 'parsed'): string; /** * Check if line contains structured data (JSON). * * @param line - Log line to check * @returns true if line contains valid JSON */ isStructured(line: string): boolean; /** * Filter log entries by criteria. * * @param entries - Array of parsed log entries * @param filter - Filter options * @returns Filtered array of entries */ filter(entries: IParsedLogEntry[], filter: ILogFilterOptions): IParsedLogEntry[]; /** * Calculate statistics for log entries. * * @param entries - Array of parsed log entries * @returns Log statistics */ calculateStats(entries: IParsedLogEntry[]): ILogStats; /** * Create initial parser state. * * @returns Fresh parser state for incremental parsing */ createInitialState(): IParserState; /** * Extract timestamp from log line. * * Handles multiple timestamp formats including: * - Double timestamp (ISO + time): 2026-02-05T22:41:05.372Z 22:41:05.372 * - Supervisord: 2026-02-05 22:22:38,372 * - Unix milliseconds: [1770328479225] * * @param line - Log line * @returns ISO timestamp string or undefined * @private */ private extractTimestamp; /** * Format timestamp for display. * * @param timestamp - ISO timestamp * @returns Formatted timestamp string * @private */ private formatTimestamp; /** * Extract tags from log line. * * @param line - Log line * @returns Array of extracted tags * @private */ private extractTags; /** * Extract message content from log line. * * Removes ALL metadata including timestamps, levels, tags, and source locations * to return only the clean message content. * * @param line - Log line * @param _timestamp - Extracted timestamp (unused, kept for API compatibility) * @param _levelMatch - Level match string (unused, kept for API compatibility) * @returns Message content * @private */ private extractMessage; /** * Parse structured data (JSON) from log line. * * @param line - Log line * @returns Parsed object or undefined * @private */ private parseStructured; /** * Get ANSI color code for log level. * * @param level - Log level * @returns ANSI SGR color code * @private */ private _getAnsiColorForLevel; } //# sourceMappingURL=LogParserService.d.ts.map