<?php
header('Content-Type: application/json');

$logfile = '/var/www/html/systapp-admin-php/logs/audit/adminpanel-audit.log';

if (!file_exists($logfile)) {
    echo json_encode([]);
    exit;
}

$lines = file($logfile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
$entries = array_map(fn($l) => json_decode($l, true), $lines);

echo json_encode(array_reverse($entries)); // newest first
?>
