Skip to content

監査ログ

Doggy は全チェーンのシステム操作監査機能を提供します。AuditService で重要な操作をすべて記録し、App\Entity\System\AuditLog に保存します。

概要

監査ログシステムは以下の要素で構成されます:

  • AuditLog エンティティsrc/Entity/System/AuditLog.php): ログの永続化
  • AuditServicesrc/Service/System/AuditService.php): ログ記録サービス
  • 監査ログの入口は App\Controller\Admin\SecurityConfigController

記録内容

各監査ログには以下が含まれます:

  • action: 操作タイプ(login_successlogin_failurecreateupdatedelete
  • category: カテゴリ(securitybusinesssystem
  • details: 操作詳細(JSON 形式)
  • performer: 操作を実行したユーザー

使用方法

php
use App\Service\System\AuditService;

class SomeService
{
    public function __construct(private AuditService $auditService) {}

    public function doSomething(): void
    {
        // 登录成功
        $this->auditService->log('login_success', 'security', [], $user);

        // 登录失败
        $this->auditService->log('login_failure', 'security', [
            'username' => $email,
            'error' => $exception->getMessage(),
        ]);

        // 数据操作
        $this->auditService->log('update', 'business', [
            'entity' => Employee::class,
            'id' => $employee->getId(),
            'changes' => $changes,
        ]);
    }
}

統合

監査ログは主要なセキュリティフローに自動統合されています:

ログイン認証

App\Security\AppCustomAuthenticator が自動的に記録します:

php
// 登录成功时
$this->auditService->log('login_success', 'security', [], $user);

// 登录失败时
$this->auditService->log('login_failure', 'security', [
    'username' => $email,
    'error' => $exception->getMessage(),
]);

セキュリティ要件

  • 監査ログは監査員のみ閲覧可能(ROLE_AUDITORThreeOfficersVoterAUDIT_VIEW 権限)
  • ログはデータベースに保存され、遡及追跡とエクスポートをサポート
  • 期間、ユーザー、操作タイプによる検索をサポート

MIT ライセンスでオープンソース | Copyright © 2026 Doggy