PHPackages                             mesa/logmiddleware - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. mesa/logmiddleware

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

mesa/logmiddleware
==================

Laravel audit trail middleware package

v1.0.0(10mo ago)03MITPHPPHP &gt;=7.4

Since Jul 8Pushed 10mo agoCompare

[ Source](https://github.com/minea123/laravel-audit-trail)[ Packagist](https://packagist.org/packages/mesa/logmiddleware)[ RSS](/packages/mesa-logmiddleware/feed)WikiDiscussions main Synced 1mo ago

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

Laravel AuditLog Middleware
===========================

[](#laravel-auditlog-middleware)

Custom Laravel middleware package to log request and response data in structured JSON format with rotating log files.

---

✨ Features
----------

[](#-features)

- Logs request metadata: IP, method, URL, user agent, session, request body, response, duration, etc.
- Outputs one compact JSON object per request
- Log rotation based on a time interval (e.g. every 5 minutes)
- Supports custom request ID for tracing

---

⚡ Installation
--------------

[](#-installation)

```
composer require mesa/logmiddleware
```

---

⚙ Configuration
---------------

[](#-configuration)

### 1. Publish Configuration (Optional)

[](#1-publish-configuration-optional)

```
php artisan vendor:publish --tag=config
```

This will create `config/auditlog.php`:

```
return [
    'base_dir' => env('AUDITLOG_BASE_DIR', storage_path('logs/audit')),
    'rotate_interval' => env('AUDITLOG_ROTATE_INTERVAL', 300),
    'level' => env('AUDITLOG_LEVEL', 'debug'),
    'enable' => env('AUDITLOG_ENABLE', true)
];
```

### 2. Set Environment Variables

[](#2-set-environment-variables)

In `.env` file:

```
AUDITLOG_BASE_DIR=/absolute/path/to/storage/logs/audit
AUDITLOG_ROTATE_INTERVAL=300
AUDITLOG_LEVEL=debug
AUDITLOG_ENABLE=true
```

### 3. Register Logging Channel

[](#3-register-logging-channel)

Add to `config/logging.php` under `channels`:

```
'auditlog' => [
    'driver' => 'monolog',
    'handler' => \Mesa\LogMiddleware\Logging\LogRotatingFileHandler::class,
    'with' => [
        'baseDir' => config('auditlog.base_dir'),
        'level' => \Monolog\Logger::toMonologLevel(config('auditlog.level')),
        'interval' => config('auditlog.rotate_interval'),
        'enable' => config('auditlog.enable')
    ],
    'formatter' => \Monolog\Formatter\LineFormatter::class,
    'formatter_with' => [
        'format' => "%message%\n",
        'allowInlineLineBreaks' => false,
        'ignoreEmptyContextAndExtra' => true,
    ],
],
```

---

🛠 Middleware Setup
------------------

[](#-middleware-setup)

### 1. Create Request ID Middleware (Optional)

[](#1-create-request-id-middleware-optional)

```
namespace App\Http\Middleware;

use Closure;
use Illuminate\Support\Str;

class RequestIdMiddleware
{
    public function handle($request, Closure $next)
    {
        $requestId = $request->header('X-Request-ID') ?? (string) Str::uuid();

        $request->attributes->set('request_id', $requestId);

        $response = $next($request);
        $response->headers->set('X-Request-ID', $requestId);

        return $response;
    }
}
```

### 2. Add Middleware to Kernel

[](#2-add-middleware-to-kernel)

In `app/Http/Kernel.php`:

```
protected $middleware = [
    // ...
    \App\Http\Middleware\RequestIdMiddleware::class,
    \Mesa\LogMiddleware\Middleware\AuditLogMiddleware::class,
];
```

> **Note:** Order matters. Request ID middleware must run before audit log middleware.

---

📊 Log Output
------------

[](#-log-output)

Log files will be stored at:

```
/storage/logs/audit/YYYYMMDD_HHMM.log

```

Each line is a compressed JSON object representing a request.

### Example:

[](#example)

```
{"ip":"127.0.0.1","method":"GET","url":"https://yourapp.test/api","user_agent":"Mozilla/...","duration":142.67,"body":{"key":"value"},"response_status":200,"ts":"2025-07-03T04:00:00Z"}
```

---

✅ You're all set!
-----------------

[](#-youre-all-set)

The middleware will now log every incoming request with full structured data into timestamped rotating log files.

Need to filter or extend logs? Just update `AuditLogMiddleware`.

---

MIT License | Maintained by @mesa

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance54

Moderate activity, may be stable

Popularity3

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity36

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

315d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/83fd1f149b7fc73b1c48e04359b64d8a39127e9e37381ebf750fd5a241debee0?d=identicon)[minea123](/maintainers/minea123)

---

Top Contributors

[![minea123](https://avatars.githubusercontent.com/u/173993684?v=4)](https://github.com/minea123 "minea123 (6 commits)")

### Embed Badge

![Health badge](/badges/mesa-logmiddleware/health.svg)

```
[![Health](https://phpackages.com/badges/mesa-logmiddleware/health.svg)](https://phpackages.com/packages/mesa-logmiddleware)
```

###  Alternatives

[barryvdh/laravel-ide-helper

Laravel IDE Helper, generates correct PHPDocs for all Facade classes, to improve auto-completion.

14.9k123.0M687](/packages/barryvdh-laravel-ide-helper)[orchestra/canvas

Code Generators for Laravel Applications and Packages

20917.2M158](/packages/orchestra-canvas)[illuminate/pipeline

The Illuminate Pipeline package.

9346.6M213](/packages/illuminate-pipeline)[illuminate/pagination

The Illuminate Pagination package.

10532.5M862](/packages/illuminate-pagination)[spatie/laravel-pjax

A pjax middleware for Laravel 5

513371.8k11](/packages/spatie-laravel-pjax)[spatie/laravel-mix-preload

Add preload and prefetch links based your Mix manifest

169176.0k2](/packages/spatie-laravel-mix-preload)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
