webqamdev/activity-logger
最新稳定版本:4.0.3
Composer 安装命令:
composer require webqamdev/activity-logger
包简介
Log every model creation, edition and deletion.
README 文档
README
The webqamdev/activity-logger package automatically log model changes from users into database and log files.
Dependencies
This package use spatie/laravel-activitylog to store logs in database. Feel free to configure it if needed or just follow Installation instructions.
Installation
You can install the package via composer:
composer require webqamdev/activity-logger
The package will automatically register itself.
Configure spatie/laravel-activitylog. By default, run those commands :
php artisan vendor:publish --provider="Spatie\Activitylog\ActivitylogServiceProvider" --tag="activitylog-migrations" php artisan migrate
You can optionally publish the config file with:
php artisan vendor:publish --provider="Webqamdev\ActivityLogger\ActivityLoggerServiceProvider" --tag="config"
Usage
Model Configuration & Detailed Logs
To enable detailed logging and ensure the logs follow the standard Spatie format (recording changes with old and
attributes values), your model must use the Spatie\Activitylog\Traits\LogsActivity trait and implement the
getActivitylogOptions method.
This is necessary to achieve the following structure in your logs (showing what changed):
[ 'old' => [ 'name' => 'original name', 'text' => 'Lorum', ], 'attributes' => [ 'name' => 'updated name', 'text' => 'Lorum', ], ]
Example:
use Illuminate\Database\Eloquent\Model; use Spatie\Activitylog\Traits\LogsActivity; use Spatie\Activitylog\LogOptions; class User extends Model { use LogsActivity; /** * Configure the activity logging rules. */ public function getActivitylogOptions(): LogOptions { return LogOptions::defaults() ->logAll() // Log all attributes... ->logOnlyDirty(); // ...but only store changes } }
Globally hide a property
Publish config file. Then add entries to properties_hidden array.
Hide a Model property
Create your model normally, then define hidden properties.
class User extends Model { /** * The attributes that shouldn't be logged in activity logger. * * @var array */ public $logAttributesToIgnore = [ 'password', 'phone', ]; ... }
Disable logs into database
Add ACTIVITY_LOGGER_TO_DATABASE=false to your .env file will prevent logger from writing into database.
Change files permission
If not already done, publish config file:
php artisan vendor:publish --provider="Webqamdev\ActivityLogger\ActivityLoggerServiceProvider" --tag="config"
Add channel.permission to your config/activitylogger.php file like this exemple:
'channel' => [ 'path' => storage_path('logs/activity.log'), 'level' => 'debug', 'days' => 14, 'permission' => 0644, // Default value, equivalent to bash's rw-r--r-- ],
Upgrading
Please see UPGRADING for details.
About
This package using Laravel 5.8 is a plugin for auto-logging activities.
Gitlab repository : Activity logger for Laravel Github repository : Activity logger for Laravel
统计信息
- 总下载量: 35.28k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Unknown
- 更新时间: 2019-11-14