benjamin-chen / table-activity-record
lumen 框架的表格操作记录
v0.1.5
2019-01-03 08:33 UTC
Requires
- php: >=7.1.3
- influxdb/influxdb-php: ^1.14
- laravel/lumen-framework: 5.7.*
Requires (Dev)
- phpunit/phpunit: ^7.5
- vlucas/phpdotenv: ^2.5
README
需求
- PHP >= 5.5.9
- lumen >= 5.7
- influxdb >= 1.7
安装
通过 Composer 安装
composer require benjamin-chen/table-activity-record
配置
Lumen 5.7
在 bootstrap/app.php 中添加服务提供者
$app->register(BenjaminChen\TableActivityRecord\ServiceProvider::class);
在 .env 中添加环境设置
INFLUXDB_HOST=your-influx-db-host
INFLUXDB_PORT=8086
INFLUXDB_DATABASE=your-influx-db-database
添加操作日志通道
'channels' => [
'operate' => [
'driver' => 'daily',
'path' => storage_path('logs/operate/operate.log'),
]
],
使用方法
在模型文件中定义模型标签
class TestModel extends Model
{
...........
public $tags = [
'a', 'b', 'c'
];
}
在模型执行创建、更新和删除方法后触发事件
use BenjaminChen\TableActivityRecord\Events\TableActionEvent;
Event::fire(new TableActionEvent('create', $model));
触发事件将在 storage/logs/operate/operate-yyyy-mm-dd.log 中记录事件数据,并将事件记录存储在 influx-db 中。
您可以使用命令 php artisan operateRecord:check 来检查本地日志是否与 influx-db 记录相同
许可
此软件包是开源软件,根据 MIT 许可证授权。