eddytim / auditlog
一个用于轻松插入、检索审计日志并向用户发送警报的库
v1.0.3
2022-02-27 08:19 UTC
This package is auto-updated.
Last update: 2024-09-27 14:20:12 UTC
README
一个用于轻松插入、检索审计日志并向用户发送警报的库
安装
可以通过Composer安装Audit Log服务提供者,通过要求包eddytim/auditlog
,并在项目的composer.json
中设置minimum-stability
为dev
(Laravel 5所需)来安装。
{ "require": { "laravel/framework": "5.0.*", "eddytim/auditlog": "^1.0.0" }, "minimum-stability": "dev" }
或者
使用Composer要求此包
composer require eddytim/auditlog
使用composer update
更新包或使用composer install
安装。
迁移
您需要运行迁移来准备日志所需的表。运行迁移:
$ php artisan migrate
配置
要插入发送警报的电子邮件地址,发布配置。您还可以配置属于审计日志的用户模型,设置外键和所有者键。您还可以设置审计日志的检索限制,默认为50
。
$ php artisan vendor:publish --provider="Eddytim\Auditlog\AuditLogServiceProvider"
config/audit.php
return [ 'send_email_to' => '', 'user_model' => App\Models\User::class, 'foreign_key' => 'user_id', 'owner_key' => 'id', 'audit_logs_limit' => 50, ];
AuditLog服务提供者自动添加到config/app.php
,如果未添加,您必须在启动Laravel应用程序时注册提供者。
在config/app.php
中找到providers
键并注册AuditLog服务提供者。
'providers' => [ // ... 'Eddytim\Auditlog\AuditLogServiceProvider', ]
(Laravel 5.1+)
'providers' => [ // ... \Eddytim\Auditlog\AuditLogServiceProvider::class, ]
示例用法
默认情况下,日志上没有警报
$log = AuditLog::store([ 'event_status' => 'SUCCESS', 'event_type' => 'Update', 'user_id' => Auth::id(), 'description' => 'Changing user name from (old value) to (new value)', 'table_name' => null, // insert a table name if you will want to track affected table 'row_id' => null // insert table row id if you will want to track specific affected record ]);
日志上有警报
// Make sure you have your mail configured and published the vendor so as to specify an email address $log = AuditLog::store([ 'event_status' => 'SUCCESS', 'event_type' => 'Update', 'user_id' => Auth::id(), 'description' => 'Changing user name from (old value) to (new value)', 'table_name' => null, // insert a table name if you will want to track affected table 'row_id' => null // insert table row id if you will want to track specific affected record ], 'This is a message to alert you on the changes');
###检索日志
// Parameter required is an integer which indicates the offset when fetching the logs /** * @param $offset */ $logs = AuditLog::getAuditLogs(0);