定制 ddelosreyes/http-requests-logger-for-laravel 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

ddelosreyes/http-requests-logger-for-laravel

Composer 安装命令:

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

包简介

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

README 文档

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-09-07