@stacksjs/stx
Version:
A performant UI Framework. Powered by Bun.
74 lines • 2.54 kB
TypeScript
import { isDevelopment } from '../env';
export declare const errorRecovery: ErrorRecovery;
// Global error logger instance
export declare const errorLogger: ErrorLogger;
export declare const devHelpers: DevHelpers;
/**
* Error recovery strategies
*
* NOTE: Auto-recovery is opt-in via configuration.
* Use configureErrorHandling({ enableAutoRecovery: true }) to enable.
*/
export declare interface ErrorRecovery {
isEnabled(): boolean
fixCommonSyntaxErrors(template: string): { fixed: string, fixes: string[] }
createFallbackContent(sectionType: string, error: Error): string
}
/**
* Error logger configuration options
*/
export declare interface ErrorLoggerOptions {
maxErrors?: number
enableFileLogging?: boolean
logFilePath?: string
logFormat?: 'json' | 'text'
maxFileSize?: number
maxLogFiles?: number
minLevel?: 'all' | 'error' | 'warning'
}
/**
* Error log entry structure
*/
export declare interface ErrorLogEntry {
timestamp: Date
error: Error
context?: unknown
level?: 'error' | 'warning' | 'info'
}
/**
* Development mode helpers
*/
export declare interface DevHelpers {
isDevelopment(): boolean
logDetailedError(error: Error, context?: unknown): void
createErrorReport(error: Error, context?: unknown): string
}
/**
* Error logging and monitoring with optional file persistence
*/
export declare class ErrorLogger {
private errors: ErrorLogEntry[];
private maxErrors: number;
private enableFileLogging: boolean;
private logFilePath: string;
private logFormat: 'json' | 'text';
private maxFileSize: number;
private maxLogFiles: number;
private minLevel: 'all' | 'error' | 'warning';
private writeQueue: Promise<void>;
constructor(options?: ErrorLoggerOptions);
configure(options: ErrorLoggerOptions): void;
log(error: Error, context?: unknown, level?: 'error' | 'warning' | 'info'): void;
private shouldLog(level: 'error' | 'warning' | 'info'): boolean;
private formatEntry(entry: ErrorLogEntry): string;
private writeToFile(entry: ErrorLogEntry): void;
private rotateIfNeeded(fs: typeof import('node:fs')): Promise<void>;
getRecentErrors(limit?: any): ErrorLogEntry[];
getErrorsByType(errorType: string): ErrorLogEntry[];
getErrorsByLevel(level: 'error' | 'warning' | 'info'): ErrorLogEntry[];
clear(): void;
clearLogFile(): Promise<void>;
getStats(): { total: number, byType: Record<string, number>, byLevel: Record<string, number> };
exportToFile(filePath: string, format?: 'json' | 'text'): Promise<void>;
flush(): Promise<void>;
}