webqamdev/activity-logger 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

webqamdev/activity-logger

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 in attribute_changes), your model must use the Spatie\Activitylog\Models\Concerns\LogsActivity trait and implement the getActivitylogOptions method.

Set $enableLoggingModelsEvents = false on the model to avoid duplicate logs (this package already listens to Eloquent events).

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\Models\Concerns\LogsActivity;
use Spatie\Activitylog\Support\LogOptions;

class User extends Model
{
    use LogsActivity;

    public bool $enableLoggingModelsEvents = false;

    /**
     * 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 requires Laravel 12+ and PHP 8.4+. It is a plugin for auto-logging model activities.

Gitlab repository : Activity logger for Laravel Github repository : Activity logger for Laravel

webqamdev/activity-logger 适用场景与选型建议

webqamdev/activity-logger 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 39.56k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2019 年 11 月 14 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 webqamdev/activity-logger 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 webqamdev/activity-logger 我们能提供哪些服务?
定制开发 / 二次开发

基于 webqamdev/activity-logger 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 39.56k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 24
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2019-11-14