PHPackages                             the-caretakers/laravel-request-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. the-caretakers/laravel-request-logger

ActiveLaravel-package[Logging &amp; Monitoring](/categories/logging)

the-caretakers/laravel-request-logger
=====================================

Log HTTP requests and responses in Laravel applications.

1.1.7(11mo ago)0107MITPHPPHP ^8.1

Since May 6Pushed 11mo agoCompare

[ Source](https://github.com/the-caretakers/laravel-request-logger)[ Packagist](https://packagist.org/packages/the-caretakers/laravel-request-logger)[ RSS](/packages/the-caretakers-laravel-request-logger/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (9)Versions (11)Used By (0)

Laravel Request Logger
======================

[](#laravel-request-logger)

[![Latest Version on Packagist](https://camo.githubusercontent.com/8b4a306969cbb8d0dbdca314e58b830ffec7f1575491a4cff8cea16c2f20ca08/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7468652d6361726574616b6572732f6c61726176656c2d726571756573742d6c6f676765722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/the-caretakers/laravel-request-logger)[![Total Downloads](https://camo.githubusercontent.com/644aa50134992fb360f00c1c3f90d074fd62fc9250a1c9700665756efeebb852/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7468652d6361726574616b6572732f6c61726176656c2d726571756573742d6c6f676765722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/the-caretakers/laravel-request-logger)

Log incoming HTTP requests and their corresponding responses within your Laravel application. This package provides middleware to capture request/response details, sanitize sensitive data, and store logs on a configurable filesystem disk (like local or S3). Includes a command for log rotation to manage retention for disk space.

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require the-caretakers/laravel-request-logger
```

Configuration
-------------

[](#configuration)

Publish the configuration file using the `vendor:publish` Artisan command:

```
php artisan vendor:publish --provider="TheCaretakers\RequestLogger\Providers\RequestLoggerServiceProvider" --tag="request-logger-config"
```

This will create a `config/request-logger.php` file. Review the configuration options:

- `disk`: Filesystem disk for storing logs (defaults to `config('filesystems.default')`). Can be set via `REQUEST_LOGGER_DISK` env variable.
- `log_profile`: (Optional) Class to determine if a request should be logged.
- `log_writer`: (Optional) Class to handle writing the log entry.
- `sensitive_keywords`: Array of keys whose values will be sanitized in logs.
- `truncate_limit`: Max length for logged string values before truncation.
- `log_path_structure`: Path format for log files (e.g., `http-logs/{Y}-{m}-{d}.log`).
- `log_format`: Log entry format (`json` recommended).
- `log_channel`: (Optional) Log via a specific Laravel log channel instead of direct filesystem access.
- `log_request_body`: Boolean to enable/disable logging request body.
- `log_response_body`: Boolean to enable/disable logging response body.

**Important:** Ensure the configured filesystem disk (e.g., `s3`) is properly set up in your `config/filesystems.php`.

Usage
-----

[](#usage)

### Middleware Registration

[](#middleware-registration)

#### Laravel 10 and below (`app/Http/Kernel.php`)

[](#laravel-10-and-below-apphttpkernelphp)

Add the `RequestLoggerMiddleware` to the desired middleware group(s) in your `app/Http/Kernel.php`:

**Web Routes:**

```
protected $middlewareGroups = [
    'web' => [
        // ... other middleware
        \TheCaretakers\RequestLogger\Http\Middleware\RequestLoggerMiddleware::class,
    ],
    // ...
];
```

**API Routes:**

```
protected $middlewareGroups = [
    // ...
    'api' => [
        // ... other middleware
        \TheCaretakers\RequestLogger\Http\Middleware\RequestLoggerMiddleware::class,
    ],
];
```

Or apply it to specific routes or route groups.

#### Laravel 11+ (`bootstrap/app.php`)

[](#laravel-11-bootstrapappphp)

In Laravel 11 and later, middleware registration is typically done in the `bootstrap/app.php` file. Use the `withMiddleware` method:

```
