ge-tracker/basic-activity-log
Composer 安装命令:
composer require ge-tracker/basic-activity-log
包简介
A very simple activity logger to monitor the users of your website or application
README 文档
README
Description
This Laravel package provides a very easy to use solution to log the activities of the users of your Laravel app. All the activities will be logged in a db-table. Optionally the activities can also be logged against the default Laravel Log Handler.
This package was originally created by Spatie, a webdesign agency in Antwerp, Belgium. It was forked on 2020-04-01 by GE Tracker and renamed, as we make use of this package in our production application.
Installation
This package can be installed through Composer.
composer require ge-tracker/basic-activity-log
This service provider will automatically be registered.
You'll also need to publish and run the migration in order to create the db-table.
php artisan vendor:publish --provider="GeTracker\BasicActivityLog\BasicActivityLogServiceProvider" --tag="migrations" php artisan migrate
Optionally you can publish the config file of this package.
php artisan vendor:publish --provider="GeTracker\BasicActivityLog\BasicActivityLogServiceProvider" --tag="config"
The configuration will be written to config/basic-basic-activitylog.php. The options provided are self explanatory.
Usage
Manual logging
Logging some activity is very simple.
//at the top of your file you should import the facade. use Activity; ... /* The log-function takes two parameters: - $text: the activity you wish to log. - $user: optional can be an user id or a user object. if not proved the id of Auth::user() will be used */ Activity::log('Some activity that you wish to log');
The string you pass to function gets written in a db-table together with a timestamp, the ip address and the user agent of the user.
Log model events
This package can log the events from your models. To do so your model must use the LogsActivity-trait and implement LogsActivityInterface.
use GeTracker\BasicActivityLog\Contracts\LogsActivity as LogsActivityContract; use GeTracker\BasicActivityLog\LogsActivity; use Illuminate\Database\Eloquent\Model; class Article extends Model implements LogsActivityContract { use LogsActivity; ...
The interface expects you to implement the getActivityDescriptionForEvent-function.
Here's an example of a possible implementation.
/** * Get the message that needs to be logged for the given event name. * * @param string $eventName * @return string */ public function getActivityDescriptionForEvent($eventName) { if ($eventName == 'created') { return 'Article "' . $this->name . '" was created'; } if ($eventName == 'updated') { return 'Article "' . $this->name . '" was updated'; } if ($eventName == 'deleted') { return 'Article "' . $this->name . '" was deleted'; } return ''; }
The result of this function will be logged, unless the result is an empty string.
Using a before handler.
If you want to disable logging under certain conditions, such as for a specific user, create a class in your application namespace that implements the GeTracker\BasicActivityLog\Contracts\BeforeHandlerInterface.
This interface defines an shouldLog() method in which you can code any custom logic to determine whether logging should be ignored or not. You must return true the call should be logged.
To en the namespaced class name to the beforeHandler field in the configuration file:
'beforeHandler' => '\App\Handlers\BeforeHandler',
For example, this callback class could look like this to disable logging a user with id of 1:
<?php namespace App\Handlers; use GeTracker\BasicActivityLog\Contracts\BeforeHandler; class BeforeHandler implements BeforeHandler { public function shouldLog($text, $userId) { if ($userId == 1) {return false;} return true; } }
Retrieving logged entries
All events will be logged in the activity_log-table. This package provides an Eloquent model to work with the table. You can use all the normal Eloquent methods that you know and love. Here's how you can get the last 100 activities together with the associated users.
use GeTracker\BasicActivityLog\Models\Activity; $latestActivities = Activity::with('user')->latest()->limit(100)->get();
Cleaning up the log
Over time your log will grow. To clean up the database table you can run this command:
Activity::cleanLog();
By default records older than 2 months will be deleted. The number of months can be modified in the config-file of the package.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email support@ge-tracker.com instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.
ge-tracker/basic-activity-log 适用场景与选型建议
ge-tracker/basic-activity-log 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3.01k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2020 年 04 月 02 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「log」 「user」 「laravel」 「activity」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 ge-tracker/basic-activity-log 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 ge-tracker/basic-activity-log 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 ge-tracker/basic-activity-log 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Stackdriver handler for Monolog (codeinternetapplications/monolog-stackdriver Fork).
Laravel 5.x.x library for integration Monolog Sentry
Pacote simplificado para persistência de logs
Collection of tools to use the full power of the Enyalius framework
Standalone replacement for php's native get_browser() function
User component for Yii2
统计信息
- 总下载量: 3.01k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 25
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-04-02