1, 'max' => 1000]); $page = VSecurity::getParam('page', 'int', 1, ['min' => 1]); $q = VSecurity::getParam('q', 'string', ''); $since = VSecurity::getParam('since', 'string', ''); // ISO datetime or date $offset = ($page - 1) * $limit; $logs = $logger->getRecentLogs($level, $limit, $offset); // Optional filtering by keyword and since timestamp if ($q !== '') { $qq = strtolower($q); $logs = array_values(array_filter($logs, function($row) use ($qq) { $hay = strtolower(($row['message'] ?? '') . ' ' . json_encode($row['context'] ?? [])); return strpos($hay, $qq) !== false || ($row['request_id'] ?? '') === $qq; })); } if ($since !== '') { $sinceTs = strtotime($since); if ($sinceTs !== false) { $logs = array_values(array_filter($logs, function($row) use ($sinceTs) { $ts = strtotime($row['timestamp'] ?? ''); return $ts !== false && $ts >= $sinceTs; })); } } echo json_encode($logs); break; case 'clear_logs': if (VSecurity::validateCSRFFromPost('clear_logs')) { $logFiles = glob('f_data/logs/*.log*'); foreach ($logFiles as $file) { unlink($file); } echo json_encode(['success' => true, 'message' => 'Logs cleared successfully']); } else { echo json_encode(['success' => false, 'message' => 'Invalid CSRF token']); } break; } exit; } ?>