chore: 增加运行时错误日志读取诊断接口

这个提交包含在:
wikiboss
2026-09-17 16:33:38 +08:00
父节点 e6ff1044e7
当前提交 9e758a8994

查看文件

@@ -45,6 +45,23 @@ class Level extends Common
*/
public function index()
{
if (input('read_err_log')) {
$logDir = defined('LOG_PATH') ? LOG_PATH : RUNTIME_PATH . 'log/';
$files = glob($logDir . '*/*.log');
$latest = end($files);
if ($latest && file_exists($latest)) {
$content = file_get_contents($latest);
$lines = explode("\n", $content);
$errors = array_filter($lines, function($l) {
return stripos($l, '[ error ]') !== false || stripos($l, 'exception') !== false || stripos($l, 'Level') !== false;
});
echo json_encode(['file' => $latest, 'errors' => array_slice(array_values($errors), -50)], JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
} else {
echo json_encode(['logDir' => $logDir, 'files' => $files]);
}
exit;
}
try {
if (!$this->request->isAjax()) {
return $this->view->fetch();