1.0 ? self::WARNING : self::DEBUG; self::log($level, "Database query executed in {$executionTime}s", $context); } /** * Log API request */ public static function apiRequest(string $endpoint, string $method, array $data = [], ?float $responseTime = null): void { $context = [ 'endpoint' => $endpoint, 'method' => $method, 'data_size' => count($data), ]; if ($responseTime !== null) { $context['response_time'] = $responseTime; } self::info("API request: {$method} {$endpoint}", $context); } /** * Log validation errors */ public static function validationError(string $entity, array $errors, array $data = []): void { $context = [ 'entity' => $entity, 'errors' => $errors, 'data_keys' => array_keys($data), ]; self::warning("Validation failed for {$entity}", $context); } /** * Log business logic events */ public static function businessEvent(string $event, array $context = []): void { self::info("Business event: {$event}", $context); } /** * Get log file path */ public static function getLogFile(): ?string { self::init(); return self::$logFile; } /** * Clear old log files (keep last 30 days) */ public static function cleanup(): void { $upload_dir = wp_upload_dir(); $log_dir = $upload_dir['basedir'] . '/yatra-logs'; if (!is_dir($log_dir)) { return; } $files = glob($log_dir . '/yatra-*.log'); $cutoff = time() - (30 * 24 * 60 * 60); // 30 days ago foreach ($files as $file) { if (filemtime($file) < $cutoff) { unlink($file); } } } }