jdenda-trox / laravel-auth-logger
使用添加的 Graylog 连接器,在 Laravel 中记录用户认证操作。
dev-master
2023-12-12 07:26 UTC
Requires
- php: ^8.0
- hedii/laravel-gelf-logger: ^8.1
- illuminate/auth: ^9.0|^10.0
- illuminate/database: ^9.0|^10.0
- illuminate/support: ^9.0|^10.0
Requires (Dev)
- nunomaduro/larastan: ^2.0
- orchestra/testbench: ^7.0|^8.0
- timacdonald/log-fake: ^2.1
This package is auto-updated.
Last update: 2024-09-12 09:06:25 UTC
README
laravel-auth-log
包会将所有默认的 Laravel 认证事件(登录、尝试、锁定等)记录到您的数据库,并可选地记录到 Graylog 实例。在配置文件中,您可以选择要记录到数据库的事件。它将保存事件名称、电子邮件、用户 ID、IP 地址和用户代理。无需其他配置。此包可用于跟踪 Laravel 应用程序中的不受欢迎的活动。
Laravel 支持
安装
1. 通过 composer 安装包
composer require jdenda-trox/laravel-auth-log
2. 发布配置文件和迁移
php artisan vendor:publish --provider="Label84\AuthLog\AuthLogServiceProvider" --tag="config" php artisan vendor:publish --provider="Label84\AuthLog\AuthLogServiceProvider" --tag="migrations"
3. 运行迁移
php artisan migrate
用法
在配置文件 config/authlog.php
中,您可以(取消)注释要记录到数据库的事件。
// config/authlog.php return [ // ... 'events' => [ \Illuminate\Auth\Events\Attempting::class, // \Illuminate\Auth\Events\Authenticated::class, \Illuminate\Auth\Events\Failed::class, \Illuminate\Auth\Events\Lockout::class, \Illuminate\Auth\Events\Login::class, \Illuminate\Auth\Events\Logout::class, \Illuminate\Auth\Events\OtherDeviceLogout::class, \Illuminate\Auth\Events\PasswordReset::class, \Illuminate\Auth\Events\Registered::class, \Illuminate\Auth\Events\Verified::class, ], ];
在同一个文件中,您还可以更改数据库连接和表名。
启用/禁用日志记录
您可以将 AUTH_LOG_ENABLED=
添加到 .env
文件中,以启用/禁用数据库的日志记录。Graylog 的配置如下。
// .env AUTH_LOG_ENABLED=true
表格式示例
测试
./vendor/bin/phpstan analyse ./vendor/bin/phpunit