/** * Log tailing operations for B2C Commerce. */ import type { B2CInstance } from '../../instance/index.js'; import type { GetRecentLogsOptions, LogEntry, TailLogsOptions, TailLogsResult } from './types.js'; /** * Parses the first line of a log entry to extract timestamp, level, and message. * * Expected format: [timestamp GMT] LEVEL context - message * Example: [2025-01-25 10:30:45.123 GMT] ERROR PipelineCallServlet|... - Error message * * The message field will contain: * - The content portion from the first line (after LEVEL) * - Plus any continuation lines (stack traces, etc.) * * If the standard B2C log format is not matched, returns an unparsed entry with only * the file, message, and raw fields. The timestamp and level fields will be undefined * in this case, but the raw log line is preserved for debugging or recovery purposes. * * @param firstLine - First line of the log entry * @param file - File name the entry came from * @param fullMessage - Complete raw message including all lines * @param pathNormalizer - Optional function to normalize paths in the message * @returns Parsed log entry; fields timestamp and level may be undefined if format doesn't match */ export declare function parseLogEntry(firstLine: string, file: string, fullMessage: string, pathNormalizer?: (msg: string) => string): LogEntry; /** * Splits content into lines, handling incomplete lines at boundaries. * Uses TextDecoder with stream mode for proper UTF-8 multi-byte character handling. * * @param content - ArrayBuffer content * @param decoder - TextDecoder instance (should be reused for streaming) * @param isComplete - Whether this is the final chunk (flush decoder) * @returns Array of complete lines (without trailing incomplete line) */ export declare function splitLines(content: ArrayBuffer, decoder: InstanceType, isComplete?: boolean): string[]; /** * Aggregates lines into multi-line log entries. * * B2C log entries can span multiple lines. A new entry starts when a line * begins with a timestamp pattern: [YYYY-MM-DD HH:MM:SS.mmm GMT] * * @param lines - Array of individual lines * @param pendingLines - Lines carried over from previous chunk (incomplete entry) * @returns Object with complete entries and any pending lines for next chunk */ export declare function aggregateLogEntries(lines: string[], pendingLines?: string[]): { entries: string[][]; pending: string[]; }; /** * Tails log files on a B2C Commerce instance. * * Continuously polls for new log content using HTTP Range requests for efficiency. * Calls the onEntry callback for each new log line. * * @param instance - B2C instance to tail logs from * @param options - Tailing options (filters, callbacks, polling interval) * @returns Tail result with stop() control and done promise * * @example * ```typescript * const result = await tailLogs(instance, { * prefixes: ['error', 'customerror'], * onEntry: (entry) => console.log(`[${entry.file}] ${entry.message}`), * onError: (err) => console.error('Tail error:', err), * }); * * // Stop after 10 seconds * setTimeout(() => result.stop(), 10000); * * // Wait for tailing to complete * await result.done; * ``` */ export declare function tailLogs(instance: B2CInstance, options?: TailLogsOptions): Promise; /** * Gets recent log entries (one-shot retrieval). * * Useful for MCP server integration or programmatic access without continuous tailing. * Reads the tail end of log files and returns parsed entries. * * @param instance - B2C instance to get logs from * @param options - Retrieval options * @returns Array of recent log entries * * @example * ```typescript * // Get the last 50 error entries * const entries = await getRecentLogs(instance, { * prefixes: ['error'], * maxEntries: 50 * }); * ``` */ export declare function getRecentLogs(instance: B2CInstance, options?: GetRecentLogsOptions): Promise;