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:
64
app/Models/ApiRequestLog.php
Normal file
64
app/Models/ApiRequestLog.php
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
* API 요청/응답 로그 모델
|
||||
*
|
||||
* @property int $id
|
||||
* @property string $method
|
||||
* @property string $url
|
||||
* @property string|null $route_name
|
||||
* @property array|null $request_headers
|
||||
* @property array|null $request_body
|
||||
* @property array|null $request_query
|
||||
* @property int $response_status
|
||||
* @property string|null $response_body
|
||||
* @property int $duration_ms
|
||||
* @property string|null $ip_address
|
||||
* @property string|null $user_agent
|
||||
* @property int|null $user_id
|
||||
* @property int|null $tenant_id
|
||||
* @property \Carbon\Carbon $created_at
|
||||
*/
|
||||
class ApiRequestLog extends Model
|
||||
{
|
||||
public $timestamps = false;
|
||||
|
||||
protected $fillable = [
|
||||
'method',
|
||||
'url',
|
||||
'route_name',
|
||||
'request_headers',
|
||||
'request_body',
|
||||
'request_query',
|
||||
'response_status',
|
||||
'response_body',
|
||||
'duration_ms',
|
||||
'ip_address',
|
||||
'user_agent',
|
||||
'user_id',
|
||||
'tenant_id',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'request_headers' => 'array',
|
||||
'request_body' => 'array',
|
||||
'request_query' => 'array',
|
||||
'response_status' => 'integer',
|
||||
'duration_ms' => 'integer',
|
||||
'user_id' => 'integer',
|
||||
'tenant_id' => 'integer',
|
||||
'created_at' => 'datetime',
|
||||
];
|
||||
|
||||
/**
|
||||
* 하루 지난 로그 삭제
|
||||
*/
|
||||
public static function pruneOldLogs(): int
|
||||
{
|
||||
return static::where('created_at', '<', now()->subDay())->delete();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user