oneseven9955/laravel-auditing-filesystem 问题修复 & 功能扩展

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

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

oneseven9955/laravel-auditing-filesystem

最新稳定版本:0.1.0

Composer 安装命令:

composer require oneseven9955/laravel-auditing-filesystem

包简介

This filesystem driver, designed for the owen-it/laravel-auditing package, facilitates storing audits in CSV files across all Laravel disks that are registered.

README 文档

README

This driver provides the functionality to save your model audit records as lines in CSV files. It is seamlessly integrated with Laravel Storage System, enabling you to use any of the registered disks specified in your application as storage destinations for the audit files.

Additionally, the driver offers flexibility in how the audit files are generated, allowing you to choose between creating a single comprehensive file or generating files for each hour of operation. Moreover, the driver can potentially improve performance by buffering the log records and then flushing them once you have completed making model changes.

Installation

To utilize this driver, you need to have owen-it/laravel-auditing: ^13.0 installed. Once this requirement is met, you can proceed to install the driver as follows:

composer require OneSeven9955/laravel-auditing-fs

Setup

If you wish to modify the default behavior of the driver, you must include the following configuration entries in config/audit.php. The drivers key in the configuration file should be structured as follows:

    // ...
    'drivers' => [
        'database' => [
            'table'      => 'audits',
            'connection' => null,
        ],
        'filesystem' => [
            'disk'      => 'local',     // The registered name of any filesystem disk in the application
            'dir'       => 'audit',     // The directory on the disk where the audit csv files will be saved
            'filename'  => 'audit.csv', // The filename of the audit file
            'rotation'  => 'single',    // One of 'single', 'daily', or 'hourly'
        ],
    ],
    // ...

Usage

You can integrate the driver into any Auditable model by following the code snippet below:

<?php
namespace App\Models;

use OneSeven9955\Auditing\Drivers\FilesystemDriver;
use Illuminate\Database\Eloquent\Model;
use OwenIt\Auditing\Contracts\Auditable;

class Article extends Model implements Auditable
{
    use \OwenIt\Auditing\Auditable;

    /**
     * Filesystem Audit Driver.
     *
     * @var \OneSeven9955\Auditing\Drivers\FilesystemDriver
     */
    protected $auditDriver = FilesystemDriver::class;

    // ...
}

To optimize the process of writing audit records, consider buffering the records and writing them in bulk rather than individually. This approach helps reduce I/O operations, such as acquiring exclusive file locks and opening files repeatedly.

You can implement this optimization by following these steps:

use OneSeven9955\Auditing\Drivers\FilesystemDriver;

app(FilesystemDriver::class)->bufferStart();
    // ...
    // PERFORM MODEL CHANGES
    // ...
app(FilesystemDriver::class)->bufferFlush(); // flush all audit records into a file at once

统计信息

  • 总下载量: 6
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-07-30