ddelosreyes/http-requests-logger-for-laravel

A simple HTTP request logger for Laravel with buffered inserts and support for both relational databases and DynamoDB.

Maintainers

Package info

github.com/delosreyesdan/http-requests-logger-for-laravel

pkg:composer/ddelosreyes/http-requests-logger-for-laravel

Statistics

Installs: 3

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

dev-main 2025-09-07 17:26 UTC

This package is auto-updated.

Last update: 2026-03-07 18:46:33 UTC


README

๐Ÿšง WORK IN PROGRESS.

Latest Version on Packagist

Yet another HTTP request logger for Laravel โ€” but built to be fast, buffered, and flexible.

This package logs incoming HTTP requests in batches to your preferred storage:

  • โœ… Database (MySQL, Postgres, SQLite, etc.)
  • โœ… Redis buffer (auto-flushed in batches)
  • ๐Ÿšง DynamoDB support (coming soon)

โœจ Features

  • ๐Ÿ”„ Buffered logging โ€” requests are first pushed to Redis for efficiency.
  • ๐Ÿ—„ Pluggable storage โ€” store logs in your DB or Redis (configurable).
  • โšก๏ธ Batch inserts โ€” reduces DB overhead by inserting multiple logs at once.
  • ๐ŸŽ› Configurable batch size & Redis connection.
  • ๐Ÿงช Pest + Testbench powered test suite with Docker setup.

๐Ÿ“ฅ Installation

Require the package via Composer:

composer require ddelosreyes/http-requests-logger-for-laravel

If auto-discovery is disabled, register the service provider manually:

// config/app.php
'providers' => [
    Ddelosreyes\\HttpRequestsLogger\\HttpRequestsLoggerServiceProvider::class,
];

Publish the config and migration:

php artisan vendor:publish --provider="Ddelosreyes\\HttpRequestsLogger\\HttpRequestsLoggerServiceProvider" --tag=config
php artisan vendor:publish --provider="Ddelosreyes\\HttpRequestsLogger\\HttpRequestsLoggerServiceProvider" --tag=migrations
php artisan migrate

โš™๏ธ Configuration

In the config/http-requests-logger.php

return [
    'storage'    => env('HTTP_REQUEST_LOGGER_STORAGE', 'database'),
    'batch_size' => env('HTTP_REQUEST_LOGGER_BATCH_SIZE', 500),
    'table'      => env('HTTP_REQUEST_LOGGER_TABLE', 'http_request_logs'),

    'redis' => [
        'scheme'   => env('REDIS_SCHEME', 'tcp'),
        'host'     => env('REDIS_HOST', '127.0.0.1'),
        'port'     => env('REDIS_PORT', 6379),
        'password' => env('REDIS_PASSWORD', null),
        'database' => env('REDIS_DB', 0),
        'timeout'  => env('REDIS_TIMEOUT', 1.5),
    ],
];

In your dotenv

HTTP_REQUEST_LOGGER_STORAGE=database
HTTP_REQUEST_LOGGER_BATCH_SIZE=500
HTTP_REQUEST_LOGGER_TABLE=http_request_logs

REDIS_SCHEME=tcp
REDIS_HOST=127.0.0.1
REDIS_PORT=6379
REDIS_PASSWORD=null
REDIS_DB=0

๐Ÿ” How It Works

  1. Every incoming request is captured (method, URL, IP, user agent, headers, body)
  2. Log payload is pushed to Redis (list)
  3. Once the buffer reaches batch_size, logs are flushed into SQL in a single insert
  4. Flush can also be triggered manually

๐Ÿ“ Logged Data

[
  'method'     => $request->getMethod(),
  'url'        => $request->getRequestUri(),
  'ip'         => $request->getClientIp(),
  'user_agent' => $request->getUserAgent(),
  'headers'    => json_encode($request->headers->all()),
  'body'       => json_encode($request->all()),
]

Usage

Option A: Middleware

// app/Http/Kernel.php
protected $middleware = [
    \Ddelosreyes\HttpRequestsLogger\Http\Middleware\LogHttpRequest::class,
];

Option B: Manually log in controller/job

use Ddelosreyes\HttpRequestsLogger\Actions\RequestLogBufferAction;

RequestLogBufferAction::add($request);

๐Ÿงช Testing

This package is built with PestPHP + Orchestra Testbench.

Run tests locally with Docker:

make build
make test