- DB: 감사 로그 테이블(audit_logs) 마이그레이션 및 인덱스 추가 - Config: audit.php 추가(AUDIT_RETENTION_DAYS, AUDIT_LOG_READS 토글) - Model/Service: AuditLog 모델, AuditLogger 서비스 생성 - 도메인 훅: ModelVersion.release(released), BomTemplate upsert/update/delete/replaceItems/clone 기록, diff 조회는 설정 기반 기록 - API: GET /api/v1/design/audit-logs 추가(FormRequest/Service/Controller, 필터 page/size/target_type/target_id/action/actor_id/from/to/sort/order) - Swagger: 감사 로그 조회 문서 추가(Design Audit 태그) - Console: audit:prune 커맨드 추가 및 스케줄러 매일 03:10 실행 등록(시스템 크론 schedule:run 필요) - Fix: PruneAuditLogs import 충돌 제거(Google ServiceControl AuditLog 제거)
43 lines
1.1 KiB
PHP
43 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Services\Audit;
|
|
|
|
use App\Models\Audit\AuditLog;
|
|
|
|
class AuditLogger
|
|
{
|
|
/**
|
|
* 감사 로그 기록
|
|
*/
|
|
public function log(
|
|
int $tenantId,
|
|
string $targetType,
|
|
?int $targetId,
|
|
string $action,
|
|
?array $before = null,
|
|
?array $after = null
|
|
): void {
|
|
try {
|
|
$request = request();
|
|
$actorId = optional(auth()->user())->id ?? null;
|
|
$ip = $request?->ip();
|
|
$ua = $request?->userAgent();
|
|
|
|
AuditLog::create([
|
|
'tenant_id' => $tenantId,
|
|
'target_type' => $targetType,
|
|
'target_id' => $targetId,
|
|
'action' => $action,
|
|
'before' => $before,
|
|
'after' => $after,
|
|
'actor_id' => $actorId,
|
|
'ip' => $ip,
|
|
'ua' => $ua,
|
|
'created_at' => now(),
|
|
]);
|
|
} catch (\Throwable $e) {
|
|
// 감사 로그 실패는 업무 흐름을 방해하지 않음
|
|
}
|
|
}
|
|
}
|