Files
citrus-cms/resources/views/admin-ajax/system-logs.php
T
2026-04-28 21:15:09 +03:00

27 lines
1004 B
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
$allLogFiles = glob(storage_path('logs/*.log')); // Tüm log dosyalarını al
$logFiles = array_filter($allLogFiles, function($file) {
// Dosya adında tarih formatı (YYYY-MM-DD) içeren dosyaları filtrele
return preg_match('/\d{4}-\d{2}-\d{2}/', basename($file));
});
$latestLogFile = array_reduce($logFiles, function($a, $b) {
return (filemtime($a) > filemtime($b)) ? $a : $b; // En son oluşturulan dosyayı bul
});
$logs = file($latestLogFile); // En son log dosyasını oku
$logs = array_reverse($logs); // Logları ters çevir
$logArray = []; // Log dizisini oluştur
foreach ($logs as $log) {
preg_match('/\[(.*?)\] (.*?): (.*)/', $log, $matches); // Log formatını ayıkla
if (count($matches) === 4) {
$logArray[] = [
'date' => $matches[1], // Tarih
'level' => $matches[2], // Log türü
'message' => $matches[3] // Log metni
];
}
}
echo json_encode_tr($logArray); // Log dizisini JSON formatında döndür