This commit is contained in:
2026-01-05 15:11:12 +09:00
parent 8338df57c9
commit da33e34d4f
6 changed files with 330 additions and 245 deletions

View File

@@ -11,12 +11,34 @@ if (! function_exists('write_custom_log')) {
@mkdir($logDir, 0777, true);
}
// --- 호출 위치 추적 로직 추가 ---
// debug_backtrace는 호출 스택을 가져옵니다.
// [0]은 현재 함수(write_custom_log), [1]은 이 함수를 호출한 곳입니다.
$bt = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2);
$caller = $bt[1] ?? null;
$fileInfo = $bt[0] ?? null; // 파일명과 라인수는 호출 시점인 0번 인덱스에 들어있음
$location = 'unknown';
if ($caller) {
$class = $caller['class'] ?? '';
$func = $caller['function'] ?? '';
$line = $fileInfo['line'] ?? '0';
// 클래스명에서 Namespace 제외하고 클래스명만 짧게 가져오기 (선택 사항)
$classShort = substr(strrchr($class, "\\"), 1) ?: $class;
$location = "{$classShort}::{$func}:{$line}";
}
// ----------------------------
$suffix = ($type === 'failed') ? '_failed' : '';
$logFile = $logDir . '/' . date('Y-m-d') . $suffix . '.log';
$timestamp = date('Y-m-d H:i:s');
$singleLine = str_replace(["\r", "\n", "\t"], " ", $message);
$formatted = "[$timestamp] [$level] $singleLine" . PHP_EOL;
// 포맷에 [$location] 추가
$formatted = "[$timestamp] [$level] [$location] $singleLine" . PHP_EOL;
@file_put_contents($logFile, $formatted, FILE_APPEND);
}