Search by

euginepj / laravel-api-logger

euginepj

Global API request and response logging middleware with visual admin dashboard for Laravel.

Package info

github.com/euginepj/laravel-api-logger

Language:Blade

pkg:composer/euginepj/laravel-api-logger

Statistics

Installs: 1

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.0 2026-10-12 11:41 UTC

This package is auto-updated.

Last update: 2026-10-12 12:29:15 UTC


README

Latest Version on Packagist Total Downloads License

A high-performance API request and response logging middleware with visual analytics and admin dashboard for Laravel.

✨ Features

  • Asynchronous Lifecycle Logging: Runs during Laravel's terminate lifecycle step to avoid slowing down API response times.
  • Visual Admin Dashboard: Inspect API calls, status codes (2xx, 4xx, 5xx), request/response headers, payload bodies, and duration.
  • Sensitive Data Masking: Automatically masks passwords, bearer tokens, API keys, and credit cards with PayloadSanitizer.
  • Flexible Storage Drivers: Supports database, file (daily logs), or both.
  • Automatic Pruning: Artisan command (php artisan api-logger:prune) to automatically clean old logs.
  • Selective Logging: Option to log only errors (>= 400) or all requests, with customizable path exclusion.

📦 Installation

Install via Composer:

composer require euginepj/laravel-api-logger

Publish configuration and run database migrations:

php artisan vendor:publish --tag=api-logger-config
php artisan vendor:publish --tag=api-logger-migrations
php artisan migrate

🚀 Usage

1. Register Middleware

Add the middleware to your api middleware group:

Laravel 11+ (bootstrap/app.php):

->withMiddleware(function (Middleware $middleware) {
    $middleware->api(append: [
        \Euginepj\ApiLogger\Http\Middleware\LogApiRequests::class,
    ]);
})

Laravel 10 (app/Http/Kernel.php):

protected $middlewareGroups = [
    'api' => [
        // ...
        \Euginepj\ApiLogger\Http\Middleware\LogApiRequests::class,
    ],
];

2. Access Admin Dashboard

Visit /admin/api-logs in your browser.

You can customize route prefix, enabled status, and middleware in config/api-logger.php.

3. Automatic Log Pruning

Schedule log cleanup in your routes/console.php or app/Console/Kernel.php:

use Illuminate\Support\Facades\Schedule;

Schedule::command('api-logger:prune')->daily();

⚙️ Configuration

Published config file: config/api-logger.php:

return [
    'enabled' => env('API_LOGGER_ENABLED', true),
    'only_errors' => env('API_LOGGER_ONLY_ERRORS', false),
    'driver' => env('API_LOGGER_DRIVER', 'database'), // database | file | both
    'prune_days' => env('API_LOGGER_PRUNE_DAYS', 30),
    'dashboard' => [
        'enabled' => env('API_LOGGER_DASHBOARD_ENABLED', true),
        'prefix' => 'admin/api-logs',
        'middleware' => ['web', 'auth'],
    ],
];

📄 License

The MIT License (MIT). Please see License File for more information.