api
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user