UNPKG

llmverify

Version:

AI Output Verification Toolkit — Local-first LLM safety, hallucination detection, PII redaction, prompt injection defense, and runtime monitoring. Zero telemetry. OWASP LLM Top 10 aligned.

145 lines (144 loc) 2.9 kB
/** * Structured Logging System * * Industry-grade logging with rotation, request tracking, and audit trails * * @module logging/logger */ import { ErrorCode } from '../errors/codes'; /** * Log levels */ export declare enum LogLevel { DEBUG = "debug", INFO = "info", WARN = "warn", ERROR = "error" } /** * Log entry structure */ export interface LogEntry { timestamp: string; level: LogLevel; requestId: string; message: string; data?: any; duration?: number; error?: { message: string; code?: ErrorCode; stack?: string; }; metadata?: { version: string; pid: number; hostname: string; }; } /** * Logger configuration */ export interface LoggerConfig { enabled: boolean; level: LogLevel; logDir?: string; maxFileSize?: number; maxFiles?: number; includeMetadata?: boolean; sanitizePII?: boolean; } /** * Logger class */ export declare class Logger { private config; private currentRequestId; private requestStartTime; constructor(config?: Partial<LoggerConfig>); /** * Ensure log directory exists */ private ensureLogDirectory; /** * Generate new request ID */ startRequest(): string; /** * End request and return duration */ endRequest(): number | null; /** * Get current request ID */ getRequestId(): string; /** * Get log file path for today */ private getLogFilePath; /** * Sanitize data to remove PII */ private sanitizeData; /** * Write log entry */ private writeLog; /** * Rotate logs if file exceeds max size */ private rotateLogsIfNeeded; /** * Clean up old log files */ private cleanupOldLogs; /** * Create log entry */ private createEntry; /** * Check if should log at level */ private shouldLog; /** * Log debug message */ debug(message: string, data?: any): void; /** * Log info message */ info(message: string, data?: any): void; /** * Log warning message */ warn(message: string, data?: any): void; /** * Log error message */ error(message: string, error?: Error, data?: any): void; /** * Read logs for a specific date */ readLogs(date?: string): LogEntry[]; /** * Get log statistics */ getStats(date?: string): { totalEntries: number; byLevel: Record<LogLevel, number>; errorCount: number; avgDuration: number; }; } /** * Get global logger */ export declare function getLogger(config?: Partial<LoggerConfig>): Logger; /** * Set global logger */ export declare function setLogger(logger: Logger): void; /** * Reset global logger */ export declare function resetLogger(): void;