alifcoder/activity-log
Composer 安装命令:
composer require alifcoder/activity-log
包简介
A simple action activity log package for Laravel.
README 文档
README
A simple, customizable Laravel package to log and store user activity across your application. Perfect for auditing, tracking changes, and monitoring actions within modules.
✨ Features
- Logs authenticated user actions and request details
- Stores activity in a dedicated
activity_logstable - Supports parent-child log relationships
- Customizable logging behavior
- Easily extendable and minimalistic
📦 Requirements
- PHP
>=8.2 - Laravel
^11.0 || ^12.0 || ^13.0
🚀 Installation
composer require alifcoder/activity-log
⚙️ Configuration & Migration
Publish the configuration and migration with:
php artisan vendor:publish --tag=activity-log
This will publish:
config/activity-log.phpdatabase/migrations/xxxx_xx_xx_xxxxxx_create_activity_logs_table.php
Then run the migration:
php artisan migrate
🧑💻 Usage
Logging a manual activity
ActivityLogger::log(new ActivityLogCreateDTO( log_type: 'custom', // optional: log type user_id: 1, // optional: user_id url: 'http://example.com', // optional: URL method: 'GET', // optional: HTTP method request_body: '{}', // optional: request body response_body: '{}', // optional: response body ... // other parameters ));
🔀 Logging for Specific Routes
If you want the activity logger to run only for selected routes, you may attach the middleware manually:
Route::post('/example', ExampleController::class)->middleware('activity_log');
🔐 Encrypted Request & Response Storage
All logged request and response bodies are stored as encrypted files for maximum data protection.
To read an encrypted stored file:
use Alif\ActivityLog\Facades\FileStorage; $content = FileStorage::readEncrypted($this->request_body);
🔑 Generating an Encryption Secret Key
Since request/response data is encrypted, the package requires a secret key.
Generate it using:
php artisan activity-log:generate-key
🌍 IP Address Details Sync
The package supports collecting additional information about user IP addresses, such as:
- Country
- City
- Coordinates
- ISP
- ASN
- and more
After installation, the package automatically registers a scheduled task:
php artisan activity-log:sync-ip-details
🧹 Pruning Old Logs
To automatically delete old or unnecessary logs, the package provides pruning support.
Add the following to your application's scheduler:
$schedule->command('model:prune', [ '--model' => [Alif\ActivityLog\Models\ActivityLog::class], ])->daily();
🧱 Table Structure: activity_logs
| Column | Type | Description |
|---|---|---|
id |
UUID | Primary key |
parent_id |
UUID | Link to parent log (optional) |
log_type |
String | Type of action (e.g. create) |
user_id |
String | Authenticated user ID |
module |
String | App module or context |
route |
String | Route name |
url |
String | Full URL accessed |
model_id |
String | Related model ID (optional) |
model_type |
String | Related model class (optional) |
user_agent |
Text | Browser/user-agent string |
created_at |
DateTime | When the log was created |
🧹 Uninstall (Clean Up)
Run this command before removing the package:
php artisan activity-log:uninstall
It will:
- Roll back the migration (calls
down()) - Delete related migration files
- Remove the config file
Then remove the package:
composer remove alifcoder/activity-log
🤝 Contributing
Pull requests are welcome! For major changes, please open an issue first.
🪪 License
MIT License © Shukhratjon Yuldashev
📡 Automatic Logging for All Requests
To log every request made to your Laravel application, you can use the provided middleware and HTTP macro.
✅ 1. Register the Middleware
In your app/Http/Kernel.php, register the middleware globally or per group:
protected $middleware = [ // ... \Alif\ActivityLog\Http\Middleware\ActivityLogMiddleware::class, ];
This will automatically log incoming HTTP requests, including route, URL, method, and user info.
✅ 2. Log Outgoing HTTP Requests
The package extends Laravel’s Http client with a loggable() macro.
Example usage:
use Illuminate\Support\Facades\Http; $response = Http::loggable()->get('https://example.com/api/data');
This logs outgoing HTTP calls made by your application.
🧩 Customization
You can customize what gets logged, ignored routes/methods, and the database connection via:
config/activity-log.php
📫 Support
If you need help, feel free to contact Shukhratjon Yuldashev on Telegram.
alifcoder/activity-log 适用场景与选型建议
alifcoder/activity-log 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 175 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 05 月 02 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 alifcoder/activity-log 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 alifcoder/activity-log 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 175
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 9
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-05-02