@tachui/devtools
Version:
Development & debugging tools for tachUI framework
287 lines • 6.84 kB
TypeScript
/**
* Error Reporting and Logging System (Phase 3.2.3)
*
* Advanced error reporting, logging, and analytics for TachUI.
* Provides structured logging, error aggregation, and reporting pipelines.
*/
import { type ErrorCategory, type ErrorSeverity, type TachUIError } from './error-boundary';
/**
* Log levels
*/
export type LogLevel = 'debug' | 'info' | 'warn' | 'error' | 'fatal';
/**
* Log entry structure
*/
export interface LogEntry {
id: string;
timestamp: number;
level: LogLevel;
message: string;
category?: string;
componentId?: string;
componentName?: string;
context?: Record<string, any>;
stack?: string;
userAgent?: string;
url?: string;
userId?: string;
sessionId?: string;
tags?: string[];
}
/**
* Error aggregation data
*/
export interface ErrorAggregation {
id: string;
message: string;
category: ErrorCategory;
severity: ErrorSeverity;
count: number;
firstSeen: number;
lastSeen: number;
affectedComponents: string[];
samples: TachUIError[];
fingerprint: string;
}
/**
* Logger interface
*/
export interface Logger {
debug(message: string, context?: Record<string, any>): void;
info(message: string, context?: Record<string, any>): void;
warn(message: string, context?: Record<string, any>): void;
error(message: string, context?: Record<string, any>): void;
fatal(message: string, context?: Record<string, any>): void;
log(level: LogLevel, message: string, context?: Record<string, any>): void;
}
/**
* Report destination interface
*/
export interface ReportDestination {
name: string;
send(data: LogEntry[] | ErrorAggregation[]): Promise<void>;
isEnabled(): boolean;
}
/**
* Reporting configuration
*/
export interface ReportingConfig {
enabled: boolean;
logLevel: LogLevel;
batchSize: number;
batchTimeout: number;
aggregationWindow: number;
maxRetries: number;
destinations: ReportDestination[];
enableContextCapture: boolean;
enableStackTrace: boolean;
enableUserTracking: boolean;
enableSessionTracking: boolean;
sensitiveKeys: string[];
enableCompression: boolean;
}
/**
* Structured logger implementation
*/
export declare class StructuredLogger implements Logger {
private entries;
private config;
private sessionId;
private userId?;
private entriesSignal;
private setEntries;
constructor(config?: Partial<ReportingConfig>);
/**
* Debug level logging
*/
debug(message: string, context?: Record<string, any>): void;
/**
* Info level logging
*/
info(message: string, context?: Record<string, any>): void;
/**
* Warning level logging
*/
warn(message: string, context?: Record<string, any>): void;
/**
* Error level logging
*/
error(message: string, context?: Record<string, any>): void;
/**
* Fatal level logging
*/
fatal(message: string, context?: Record<string, any>): void;
/**
* Generic logging method
*/
log(level: LogLevel, message: string, context?: Record<string, any>): void;
/**
* Check if should log at given level
*/
private shouldLog;
/**
* Add log entry
*/
private addEntry;
/**
* Sanitize context to remove sensitive data
*/
private sanitizeContext;
/**
* Setup batch processing
*/
private setupBatchProcessing;
/**
* Flush current batch of log entries
*/
private flushBatch;
/**
* Send data with retry logic
*/
private sendWithRetry;
/**
* Sleep for specified duration
*/
private sleep;
/**
* Generate unique ID
*/
private generateId;
/**
* Generate session ID
*/
private generateSessionId;
/**
* Set user ID for tracking
*/
setUserId(userId: string): void;
/**
* Get log entries
*/
getEntries(): LogEntry[];
/**
* Get entries signal
*/
getEntriesSignal(): () => LogEntry[];
/**
* Add destination
*/
addDestination(destination: ReportDestination): void;
/**
* Remove destination
*/
removeDestination(name: string): void;
/**
* Clear all log entries
*/
clear(): void;
}
/**
* Error aggregator
*/
export declare class ErrorAggregator {
private aggregations;
private config;
private aggregationsSignal;
private setAggregations;
constructor(config?: Partial<ReportingConfig>);
/**
* Aggregate error
*/
aggregateError(error: TachUIError): void;
/**
* Generate error fingerprint for grouping
*/
private generateFingerprint;
/**
* Setup cleanup of old aggregations
*/
private setupCleanup;
/**
* Cleanup old aggregations
*/
private cleanupOldAggregations;
/**
* Get aggregations
*/
getAggregations(): ErrorAggregation[];
/**
* Get aggregations signal
*/
getAggregationsSignal(): () => ErrorAggregation[];
/**
* Get top errors by count
*/
getTopErrors(limit?: number): ErrorAggregation[];
/**
* Clear aggregations
*/
clear(): void;
}
/**
* Built-in report destinations
*/
export declare const reportDestinations: {
/**
* Console destination
*/
console: ReportDestination;
/**
* Local storage destination
*/
localStorage: ReportDestination;
/**
* Create HTTP destination
*/
createHttpDestination(endpoint: string, apiKey?: string): ReportDestination;
/**
* Create webhook destination
*/
createWebhookDestination(webhookUrl: string, options?: {
format?: "slack" | "discord" | "teams" | "generic";
onlyErrors?: boolean;
}): ReportDestination;
};
/**
* Global logger instance
*/
export declare const globalLogger: StructuredLogger;
/**
* Global error aggregator
*/
export declare const globalErrorAggregator: ErrorAggregator;
/**
* Setup error reporting integration
*/
export declare function setupErrorReporting(config?: Partial<ReportingConfig>): void;
/**
* Reporting utilities
*/
export declare const reportingUtils: {
/**
* Setup development reporting
*/
setupDevelopment(): void;
/**
* Setup production reporting
*/
setupProduction(config: {
endpoint?: string;
apiKey?: string;
webhookUrl?: string;
logLevel?: LogLevel;
}): void;
/**
* Create custom logger
*/
createLogger(name: string, config?: Partial<ReportingConfig>): Logger;
/**
* Get error report
*/
getErrorReport(): {
logs: LogEntry[];
aggregations: ErrorAggregation[];
statistics: any;
};
};
//# sourceMappingURL=error-reporting.d.ts.map