PHPackages                             adithwidhiantara/laravel-async-audit-logger - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Logging &amp; Monitoring](/categories/logging)
4. /
5. adithwidhiantara/laravel-async-audit-logger

ActiveLibrary[Logging &amp; Monitoring](/categories/logging)

adithwidhiantara/laravel-async-audit-logger
===========================================

High performance async audit logger

1.0.0(5mo ago)10MITPHPPHP ^8.1CI passing

Since Jan 14Pushed 5mo agoCompare

[ Source](https://github.com/adith-widhiantara/laravel-async-audit-logger)[ Packagist](https://packagist.org/packages/adithwidhiantara/laravel-async-audit-logger)[ RSS](/packages/adithwidhiantara-laravel-async-audit-logger/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (2)Versions (2)Used By (0)

Laravel Async Audit Logger
==========================

[](#laravel-async-audit-logger)

[![codecov](https://camo.githubusercontent.com/00b3cd7449eb129ad43aa83bef82d9801e68b5aadfcfac3928e782c655957887/68747470733a2f2f636f6465636f762e696f2f6769746875622f61646974682d7769646869616e746172612f6c61726176656c2d6173796e632d61756469742d6c6f676765722f67726170682f62616467652e7376673f746f6b656e3d5846463855315431544b)](https://codecov.io/github/adith-widhiantara/laravel-async-audit-logger)

**High-Performance, Zero-Latency Audit Trail for Enterprise Laravel Applications.**

This package provides an asynchronous audit logging system using **Redis** as a buffer and a **Daemon Worker** for bulk database insertion. It is designed to handle high-traffic applications where traditional synchronous logging would cause performance bottlenecks.

🚀 Why use this?
---------------

[](#-why-use-this)

Traditional audit loggers insert a row into the database *synchronously* during the HTTP request.

- **Problem:** If you have 1,000 requests/sec, you are hitting the DB with 2,000 queries/sec (1 transaction + 1 log). This slows down response time and risks locking the table.
- **Solution:** This package pushes logs to Redis (memory) in &lt;1ms. A background worker then processes them in batches (e.g., 100 logs at once). The user gets an instant response, and the database load is reduced by up to 90%.

📋 Requirements
--------------

[](#-requirements)

- PHP ^8.1
- Laravel 10.x, 11.x, or 12.x
- **Redis Server** (Required for Production)
- PHP Extensions: `pcntl` (for worker signals), `redis`

📦 Installation
--------------

[](#-installation)

1. **Install via Composer:**

    ```
    composer require adithwidhiantara/laravel-async-audit-logger
    ```
2. **Publish Configuration &amp; Migrations:**

    ```
    php artisan vendor:publish --provider="Adithwidhiantara\Audit\AuditingServiceProvider"
    ```
3. **Run Migrations:**

    ```
    php artisan migrate
    ```
4. **Environment Setup (.env):**Add these configurations to your `.env` file:

    ```
    # Driver: 'redis' (Production) or 'sync' (Local/Debugging)
    AUDIT_DRIVER=redis

    # Redis Connection (Recommend using a separate DB index, e.g., 'audit')
    AUDIT_REDIS_CONNECTION=default
    AUDIT_REDIS_KEY=audit_pkg:buffer

    # Worker Tuning
    AUDIT_BATCH_SIZE=100
    AUDIT_FLUSH_INTERVAL=5
    AUDIT_PRUNE_DAYS=90
    ```

🛠 Usage
-------

[](#-usage)

### 1. Attach to Models

[](#1-attach-to-models)

Simply use the `Auditable` trait on any Eloquent model you want to track.

```
namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Adithwidhiantara\Audit\Traits\Auditable; //
