abdulbaset/activity-tracker
Composer 安装命令:
composer require abdulbaset/activity-tracker
包简介
A comprehensive activity Tracker for Laravel projects.
关键字:
README 文档
README
Activity Tracker Package
A comprehensive activity tracking package for Laravel applications that logs various types of activities including authentication events, model changes, exceptions, route access, and database queries.
Features
- 🔐 Authentication Tracking: Login, logout, failed attempts, lockouts, registrations, email verifications, and password resets
- 📝 Model Changes: Create, update, delete, force delete, and restore operations
- ⚠️ Exception Logging: Various HTTP and system exceptions
- 🛣️ Route Access: Track accessed routes with request details
- 🔍 Query Logging: Monitor database queries with execution time
- 📱 Device Information: Browser, operating system, and device type detection
- 🔄 Flexible Storage: Store logs in database or files
- ⚙️ Highly Configurable: Extensive configuration options for each feature
Changelog
All notable changes to this project will be documented in the CHANGELOG.md file.
The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.
Installation
You can install the package via composer:
composer require abdulbaset/activity-tracker
Configuration
Publish the configuration file:
php artisan vendor:publish --provider="Abdulbaset\ActivityTracker\Providers\ActivityTrackerServiceProvider"
This will create a config/activity-tracker.php file where you can configure various aspects of the package.
Migrations
After installing the package, you need to run the migrations to create the required database tables. To do this, use the following Artisan command:
php artisan migrate --path=vendor/abdulbaset/activity-tracker/src/database/migrations
Basic Usage
Manual Logging
use ActivityTracker; // Simple activity logging ActivityTracker::log('User Profile', 'User updated their profile'); // Detailed activity logging ActivityTracker::log( 'Order Created', 'New order #123 was created', [ 'properties' => [ 'order_id' => 123, 'amount' => 99.99 ] ] );
Model Tracking
Add the Trackable trait to your model:
use Abdulbaset\ActivityTracker\Traits\Trackable; class User extends Model { use Trackable; }
Configuration Options
General Configuration
return [ 'enabled' => env('ACTIVITY_TRACKER_ENABLED', true), 'log_method' => env('ACTIVITY_TRACKER_LOG_METHOD', 'database'), // 'database' or 'file' 'log_file_path' => storage_path('logs/activity_tracker.log'), ];
Authentication Events
'auth' => [ 'enabled' => true, 'events' => [ 'login' => true, 'logout' => true, 'failed' => true, 'lockout' => true, 'registered' => true, 'verified' => true, 'password_reset' => true, ], ],
Model Events
'models' => [ 'enabled' => true, 'events' => [ 'creating' => true, 'created' => true, 'updating' => true, 'updated' => true, 'deleting' => true, 'deleted' => true, 'force_deleting' => true, 'force_deleted' => true, 'restoring' => true, 'restored' => true, ], 'full_model_data' => false, ],
Exception Tracking
'exceptions' => [ 'enabled' => true, 'events' => [ 'not_found' => true, 'unauthorized' => true, 'method_not_allowed' => true, 'too_many_requests' => true, 'conflict' => true, 'unprocessable_entity' => true, 'access_denied' => true, 'gone' => true, 'precondition_failed' => true, 'unsupported_media_type' => true, 'general' => true, ], 'include_trace' => false, ],
Exclusions
'exclude' => [ 'routes' => [ 'horizon*', 'nova*', '_debugbar*', ], 'models' => [], 'model_attributes' => [ 'password', 'remember_token', 'api_token', // ... other sensitive fields ], ],
Database Schema
The package creates an activities table with the following structure:
| Column | Type | Description |
|---|---|---|
| id | bigint | Primary key |
| subject | string | Activity subject |
| causer_type | string | Model type of the causer |
| causer_id | bigint | ID of the causer |
| model_type | string | Related model type |
| model_id | bigint | Related model ID |
| event | string | Event type |
| before | json | Previous state (for updates) |
| after | json | New state (for updates) |
| ip | string | IP address |
| headers | json | Request headers |
| query_parameters | json | URL query parameters |
| request_method | string | HTTP method |
| browser | string | Browser information |
| device_type | string | Device type |
| operating_system | string | OS information |
| referring_url | string | Referrer URL |
| current_url | string | Current URL |
| description | text | Activity description |
| properties | json | Additional properties |
| created_at | timestamp | Creation timestamp |
| updated_at | timestamp | Update timestamp |
API Resource
The package includes an API resource for formatting activity logs:
use Abdulbaset\ActivityTracker\Resources\ActivityTrackerResource; // In your controller public function index() { $activities = ActivityTracker::latest()->paginate(); return ActivityTrackerResource::collection($activities); }
Events
The package tracks the following events:
Authentication Events
- Login
- Logout
- Failed Login
- Lockout
- Registration
- Email Verification
- Password Reset
Model Events
- Creating/Created
- Updating/Updated
- Deleting/Deleted
- Force Deleting/Force Deleted
- Restoring/Restored
Exception Events
- Not Found
- Unauthorized
- Method Not Allowed
- Too Many Requests
- Conflict
- Unprocessable Entity
- Access Denied
- Gone
- Precondition Failed
- Unsupported Media Type
- General Exceptions
Security
If you discover any security-related issues, please email AbdulbasetRedaSayedHF@Gmail.com instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.
Support
For support:
- Email: AbdulbasetRedaSayedHF@Gmail.com
- Create an issue in the GitHub repository
Donations 💖
Maintaining this package takes time and effort. If you’d like to support its development and keep it growing, you can:
- 🌟 Star this repository
- 📢 Sharing it with others
- 🛠️ Contribute by reporting issues or suggesting features
- ☕ Buy me a coffee
- ❤️ Become a sponsor on GitHub Sponsors
- 💵 Make a one-time donation via PayPal
Your support means a lot to me! Thank you for making this possible. 🙏
abdulbaset/activity-tracker 适用场景与选型建议
abdulbaset/activity-tracker 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 14 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 07 月 27 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「logging」 「package」 「php」 「events」 「laravel」 「activity」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 abdulbaset/activity-tracker 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 abdulbaset/activity-tracker 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 abdulbaset/activity-tracker 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A Zend Framework module that sets up Monolog for logging in applications.
Asynchronous Sentry for Symfony - Fire and forget
Stackdriver handler for Monolog (codeinternetapplications/monolog-stackdriver Fork).
High-performance, zero-dependency PSR-3 logger for MonkeysLegion with structured logging, handlers, processors, and PHP 8.4 features.
Simple ASCII output of array data
统计信息
- 总下载量: 14
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 15
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-07-27