setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); echo "=== SYNC LOG VIEWER ===\n\n"; // Get recent sync logs $stmt = $pdo->prepare(" SELECT sl.*, s.display_name as source_name FROM sync_logs sl JOIN sources s ON sl.source_id = s.id ORDER BY sl.created_at DESC LIMIT 10 "); $stmt->execute(); $logs = $stmt->fetchAll(PDO::FETCH_ASSOC); if (empty($logs)) { echo "No sync logs found. Run a sync operation first.\n"; exit(0); } echo "RECENT SYNC OPERATIONS:\n"; echo str_repeat("-", 80) . "\n"; foreach ($logs as $log) { $status = strtoupper($log['status']); $statusColor = match($log['status']) { 'completed' => '✅', 'failed' => '❌', 'running' => '🔄', default => '❓' }; echo "{$statusColor} {$log['source_name']} - {$status} - {$log['created_at']}\n"; echo " Type: {$log['sync_type']} | Processed: {$log['processed_items']} | New: {$log['new_items']} | Updated: {$log['updated_items']}\n"; if ($log['message']) { echo " Message: {$log['message']}\n"; } if ($log['errors']) { $errors = json_decode($log['errors'], true); if (is_array($errors)) { echo " Errors: " . implode(', ', $errors) . "\n"; } } echo "\n"; } // Check for log files $logFiles = glob('logs/*.log'); if (!empty($logFiles)) { echo "\nLOG FILES AVAILABLE:\n"; echo str_repeat("-", 80) . "\n"; // Sort by modification time, newest first usort($logFiles, function($a, $b) { return filemtime($b) - filemtime($a); }); foreach (array_slice($logFiles, 0, 5) as $logFile) { $size = filesize($logFile); $modified = date('Y-m-d H:i:s', filemtime($logFile)); echo "📄 " . basename($logFile) . " ({$size} bytes) - {$modified}\n"; } echo "\nTo view a specific log file, run: tail -f logs/filename.log\n"; } else { echo "\nNo log files found yet. Log files are created during sync operations.\n"; } } catch (Exception $e) { echo "Error: " . $e->getMessage() . "\n"; echo "Make sure your database is set up correctly.\n"; exit(1); }