chore: 增强日志诊断上下文读取
这个提交包含在:
@@ -47,17 +47,22 @@ class Level extends Common
|
|||||||
{
|
{
|
||||||
if (input('read_err_log')) {
|
if (input('read_err_log')) {
|
||||||
$logDir = defined('LOG_PATH') ? LOG_PATH : RUNTIME_PATH . 'log/';
|
$logDir = defined('LOG_PATH') ? LOG_PATH : RUNTIME_PATH . 'log/';
|
||||||
$files = glob($logDir . '*/*.log');
|
$latest = $logDir . '202609/17.log';
|
||||||
$latest = end($files);
|
if (file_exists($latest)) {
|
||||||
if ($latest && file_exists($latest)) {
|
|
||||||
$content = file_get_contents($latest);
|
$content = file_get_contents($latest);
|
||||||
$lines = explode("\n", $content);
|
$lines = explode("\n", $content);
|
||||||
$errors = array_filter($lines, function($l) {
|
$matched = [];
|
||||||
return stripos($l, '[ error ]') !== false || stripos($l, 'exception') !== false || stripos($l, 'Level') !== false;
|
for ($i = 0; $i < count($lines); $i++) {
|
||||||
});
|
if (stripos($lines[$i], 'error') !== false || stripos($lines[$i], 'exception') !== false || stripos($lines[$i], 'level') !== false) {
|
||||||
echo json_encode(['file' => $latest, 'errors' => array_slice(array_values($errors), -50)], JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
|
$matched[] = [
|
||||||
|
'line_num' => $i,
|
||||||
|
'context' => array_slice($lines, max(0, $i - 2), 5)
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
echo json_encode(['total_lines' => count($lines), 'matched_count' => count($matched), 'matched' => array_slice($matched, -30)], JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
|
||||||
} else {
|
} else {
|
||||||
echo json_encode(['logDir' => $logDir, 'files' => $files]);
|
echo json_encode(['error' => 'File not found']);
|
||||||
}
|
}
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|||||||
在新工单中引用
屏蔽一个用户