feat: API 요청/응답 로깅 시스템 추가
- api_request_logs 테이블 생성 (하루치만 보관) - LogApiRequest 미들웨어로 DB + 로그 파일 이중 저장 - 날짜별 로그 파일: storage/logs/api/api-YYYY-MM-DD.log - 민감 데이터 자동 마스킹 (password, token 등) - api-log:prune 스케줄러로 매일 03:00 자동 정리
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('api_request_logs', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('method', 10)->comment('HTTP 메서드');
|
||||
$table->string('url', 2048)->comment('요청 URL');
|
||||
$table->string('route_name')->nullable()->comment('라우트 이름');
|
||||
$table->json('request_headers')->nullable()->comment('요청 헤더');
|
||||
$table->json('request_body')->nullable()->comment('요청 바디');
|
||||
$table->json('request_query')->nullable()->comment('쿼리 파라미터');
|
||||
$table->unsignedSmallInteger('response_status')->comment('응답 상태 코드');
|
||||
$table->longText('response_body')->nullable()->comment('응답 바디');
|
||||
$table->unsignedInteger('duration_ms')->comment('처리 시간 (ms)');
|
||||
$table->string('ip_address', 45)->nullable()->comment('클라이언트 IP');
|
||||
$table->string('user_agent', 512)->nullable()->comment('User Agent');
|
||||
$table->unsignedBigInteger('user_id')->nullable()->comment('사용자 ID');
|
||||
$table->unsignedBigInteger('tenant_id')->nullable()->comment('테넌트 ID');
|
||||
$table->timestamp('created_at')->useCurrent()->comment('생성일시');
|
||||
|
||||
$table->index('created_at');
|
||||
$table->index(['method', 'response_status']);
|
||||
$table->index('user_id');
|
||||
$table->index('tenant_id');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('api_request_logs');
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user