threls/activity-log
Composer 安装命令:
composer require threls/activity-log
包简介
This is my package activity-log
关键字:
README 文档
README
This is where your description should go. Limit it to a paragraph or two. Consider adding a small example.
Support us
We invest a lot of resources into creating best in class open source packages. You can support us by buying one of our paid products.
We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on our contact page. We publish all received postcards on our virtual postcard wall.
Installation
You can install the package via composer:
composer require threls/activity-log
You can publish and run the migrations with:
php artisan vendor:publish --tag="activity-log-migrations"
php artisan migrate
You can publish the config file with:
php artisan vendor:publish --tag="activity-log-config"
This is the contents of the published config file:
return [ 'enabled' => env('ACTIVITY_LOG_ENABLED', true), 'log_events' => [ 'on_create' => true, 'on_update' => true, 'on_delete' => true, 'on_login' => true, ], // When true, updates will only log changed (dirty) attributes 'log_only_dirty' => true, // The User model class used to resolve causer name/id 'user_model' => '\App\Models\User', // Which attribute on the causer to display in descriptions (e.g. name/email) 'causer_name_attribute' => 'name', // Global fallback identifier used in descriptions when a model doesn't override it 'default_log_identifier' => 'id', // API listing pagination size 'log_pagination' => 20, // Middleware used by the built-in logs API route 'api_route_middleware' => 'auth:sanctum', // Number of days to retain logs before pruning (default 365) 'retention_days' => 365, ];
Usage
- Add the
LogsActivitytrait to any model you want to track. - Implement
ActivityLogContractto strongly define your model's logging configuration. - By default, descriptions are standardized as:
"{causerName} {verb} {ModelName} '{identifier}'".
Basic
use Threls\ThrelsActivityLog\Traits\LogsActivity; class Product extends Model { use LogsActivity; }
This will emit logs like: Sabina created Product '42' using the global default_log_identifier.
Per-model configuration via properties (no interface)
class Product extends Model { use LogsActivity; public ?array $logAttributes = ['name', 'price']; public ?array $ignoreAttributes = ['updated_at']; public ?bool $logOnlyDirty = true; // only diffs on update public ?string $logIdentifier = 'name'; // used in description }
Strict configuration via interface
use Threls\ThrelsActivityLog\Contracts\ActivityLogContract; use Threls\ThrelsActivityLog\Enums\ActivityLogTypeEnum; class Product extends Model implements ActivityLogContract { use LogsActivity; public function getLogAttributes(): array|string|null { return ['name', 'price']; } public function getIgnoreAttributes(): array|string|null { return ['updated_at']; } public function getLogOnlyDirty(): ?bool { return true; } public function getLogIdentifier(): ?string { return 'name'; } }
CLI / Queues safety
- The package guards request-dependent values (user agent, IP). In non-HTTP contexts, defaults like
unknownand127.0.0.1are used.
Maintenance
Log Pruning (Recommended)
This package supports Laravel's native model pruning. To keep your activity_log table small, you should schedule the model:prune command in your application's routes/console.php (or app/Console/Kernel.php for older Laravel versions):
use Illuminate\Support\Facades\Schedule; use Threls\ThrelsActivityLog\Models\ActivityLog; Schedule::command('model:prune', [ '--model' => [ActivityLog::class], ])->daily();
You can configure the retention period in config/activity-log.php:
'retention_days' => 365, // Keep logs for 1 year
Manual Cleanup
Alternatively, you can manually delete old logs using the provided command:
# Deletes logs older than 30 days php artisan activity-log:delete --older-than-days=30 # Deletes logs using the 'retention_days' from config php artisan activity-log:delete
Built-in API to list logs
GET /threls-activity-log/logs
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.
threls/activity-log 适用场景与选型建议
threls/activity-log 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.55k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 02 月 12 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「activity-log」 「threls」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 threls/activity-log 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 threls/activity-log 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 threls/activity-log 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Audit logging, activity tracking, exports, alerts, and dashboards for Filament admin panels.
This is my package snomed-ct-for-laravel
This is my package laravelmoney
This is my package check-env
Symfony Activity Log Bundle
Activity logger for filament
统计信息
- 总下载量: 2.55k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 3
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-02-12