공통화 작업 및 워커 해더
This commit is contained in:
@@ -81,27 +81,35 @@ class WorkerLog extends BaseController
|
||||
$lines = file($filePath, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
|
||||
|
||||
foreach ($lines as $line) {
|
||||
// 로그 포맷: [2025-12-22 10:30:45] [INFO] [NaverWorker::run:95] 메시지
|
||||
if (preg_match('/\[(.+?)\]\s*\[(.+?)\]\s*(?:\[(.+?)\]\s*)?(.+)/', $line, $matches)) {
|
||||
$logs[] = [
|
||||
'timestamp' => $matches[1],
|
||||
'level' => $matches[2],
|
||||
'location' => $matches[3] ?? '',
|
||||
'message' => $matches[4]
|
||||
];
|
||||
} else {
|
||||
// 파싱 실패한 경우 원본 그대로
|
||||
$logs[] = [
|
||||
'timestamp' => date('Y-m-d H:i:s'),
|
||||
'level' => 'UNKNOWN',
|
||||
'location' => '',
|
||||
'message' => $line
|
||||
];
|
||||
}
|
||||
$logs[] = $this->parseLogLine($line);
|
||||
}
|
||||
|
||||
return $logs;
|
||||
}
|
||||
|
||||
/**
|
||||
* 로그 한 줄 파싱
|
||||
*/
|
||||
private function parseLogLine($line)
|
||||
{
|
||||
// 로그 포맷: [2025-12-22 10:30:45] [INFO] [NaverWorker::run:95] 메시지
|
||||
if (preg_match('/\[(.+?)\]\s*\[(.+?)\]\s*(?:\[(.+?)\]\s*)?(.+)/', $line, $matches)) {
|
||||
return [
|
||||
'timestamp' => $matches[1],
|
||||
'level' => $matches[2],
|
||||
'location' => $matches[3] ?? '',
|
||||
'message' => $matches[4]
|
||||
];
|
||||
}
|
||||
|
||||
// 파싱 실패한 경우 원본 그대로
|
||||
return [
|
||||
'timestamp' => date('Y-m-d H:i:s'),
|
||||
'level' => 'UNKNOWN',
|
||||
'location' => '',
|
||||
'message' => $line
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 로그 파일이 존재하는 날짜 목록 가져오기
|
||||
@@ -151,14 +159,7 @@ class WorkerLog extends BaseController
|
||||
$newLines = array_slice($lines, $lastId);
|
||||
|
||||
foreach ($newLines as $line) {
|
||||
if (preg_match('/\[(.+?)\]\s*\[(.+?)\]\s*(?:\[(.+?)\]\s*)?(.+)/', $line, $matches)) {
|
||||
$newLogs[] = [
|
||||
'timestamp' => $matches[1],
|
||||
'level' => $matches[2],
|
||||
'location' => $matches[3] ?? '',
|
||||
'message' => $matches[4]
|
||||
];
|
||||
}
|
||||
$newLogs[] = $this->parseLogLine($line);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user