PHPackages                             aymanalhattami/log-request-response - 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. aymanalhattami/log-request-response

ActiveLibrary[Logging &amp; Monitoring](/categories/logging)

aymanalhattami/log-request-response
===================================

Log request, response, headers, method, IP address and URL

0.0.23(2y ago)038MITPHPPHP ^8.0|^8.1|^8.2|^8.3

Since Mar 21Pushed 2y ago1 watchersCompare

[ Source](https://github.com/aymanalhattami/log-request-response)[ Packagist](https://packagist.org/packages/aymanalhattami/log-request-response)[ Docs](https://github.com/aymanalhattami/log-request-response)[ RSS](/packages/aymanalhattami-log-request-response/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (3)Versions (24)Used By (0)

Log Request and Response
========================

[](#log-request-and-response)

[![Latest Version on Packagist](https://camo.githubusercontent.com/02eb52c1b44fbd8a861c89c5292e6018883dd536e856e069777ea7aaccd12817/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f61796d616e616c68617474616d692f6c6f672d726571756573742d726573706f6e73652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/aymanalhattami/log-request-response)[![Total Downloads](https://camo.githubusercontent.com/545786977ead69bc85b04b2a564f608f5b6841c2eac40a58f3e7551aae9ddfd7/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f61796d616e616c68617474616d692f6c6f672d726571756573742d726573706f6e73652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/aymanalhattami/log-request-response)

Log request, response, headers, method, IP address and URL

> ***NOTE:***Logs can be invaluable for debugging issues. By reviewing the request and response data, developers can trace what data was sent and received, and identify where things may have gone wrong

- Useful for logging APIs requests and responses
- Enable/disable logging request
- Enable/disable logging response
- Enable/disable logging headers
- You can specify which request data should be logged
- You can specify which response data should be logged
- You can specify which URLs should be logged

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

[](#installation)

You can install the package via composer:

```
composer require aymanalhattami/log-request-response
```

Usage
-----

[](#usage)

### Log request and response

[](#log-request-and-response-1)

```
use Illuminate\Support\Facades\Route;
use AymanAlhattami\LogRequestResponse\Http\Middleware\LogRequestResponseMiddleware;
use App\Http\Controllers\ExampleController;

# Log all routes
Route::middleware(LogRequestResponseMiddleware::class)->group(function() {
    // routes
});

# Log single route
Route::get('example', ExampleController::class)->middleware(LogRequestResponseMiddleware::class);
```

### Log request

[](#log-request)

```
use Illuminate\Support\Facades\Route;
use AymanAlhattami\LogRequestResponse\Http\Middleware\LogRequestMiddleware;
use App\Http\Controllers\ExampleController;

# Log all routes
Route::middleware(LogRequestMiddleware::class)->group(function() {
    // routes
});

# Log single route
Route::get('example', ExampleController::class)->middleware(LogRequestMiddleware::class);
```

### Log response

[](#log-response)

```
use Illuminate\Support\Facades\Route;
use AymanAlhattami\LogRequestResponse\Http\Middleware\LogResponseMiddleware;
use App\Http\Controllers\ExampleController;

# Log all routes
Route::middleware(LogResponseMiddleware::class)->group(function() {
    // routes
});

# Log single route
Route::get('example', ExampleController::class)->middleware(LogResponseMiddleware::class);
```

### Log headers

[](#log-headers)

```
use Illuminate\Support\Facades\Route;
use AymanAlhattami\LogRequestResponse\Http\Middleware\LogHeadersMiddleware;
use App\Http\Controllers\ExampleController;

# Log all routes
Route::middleware(LogHeadersMiddleware::class)->group(function() {
    // routes
});

# Log single route
Route::get('example', ExampleController::class)->middleware(LogHeadersMiddleware::class);
```

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

[](#configuration)

```
return [
    /* Defines the logging level for recording request and response logs. Default: 'info'. */
    'log_level' => env('REQUEST_RESPONSE_LOG_LEVEL', 'info'),

    'request' => [
        /* Determines whether logging of HTTP requests is enabled. */
        'enabled' => env('LOG_REQUEST', true),

        /* Title or prefix for request logs, making them easily identifiable. */
        'title' => env('LOG_REQUEST_TITLE', 'Request'),

        /* Specifies whether headers should be included in the request log. */
        'headers' => env('LOG_HEADERS_WITH_REQUEST', true),

        /* Indicates whether the request URL should be logged. */
        'url' => env('LOG_REQUEST_URL', true),

        /* Determines whether the HTTP method should be logged. */
        'method' => env('LOG_REQUEST_METHOD', true),

        /* Specifies whether the IP address of the requester should be logged. */
        'ip' => env('LOG_REQUEST_IP', true),

        /* Indicates whether information about the authenticated user should be included in the request log. */
        'auth_user' => env('LOG_AUTH_USER_WITH_REQUEST', true),

        /* Specifies whether a unique identifier for the request should be logged. */
        'request_id' => env('LOG_REQUEST_ID_WITH_REQUEST', true),

        /**
         * Specifying which request data should be logged.
         * if 'only' has data, then 'except' will be ignored.
         * if 'except' has data, then 'only' will be ignored.
         * if both 'only' and 'except' are empty, then all data will be logged.
         * if both 'only' and 'except' are not empty, then only the data specified in 'only' will be logged.
         * if 'only' is empty, but 'except' is not empty, then all data except the data specified in 'except' will be logged.
         * if 'only' is not empty, but 'except' is empty, then only the data specified in 'only' will be logged.
         */
        'data' => [
            'only' => [],
            'except' => ['password', 'password_confirmation'],
        ],

        /**
         * Specifying which URLs should be logged.
         * if 'only' has data, then 'except' will be ignored.
         * if 'except' has data, then 'only' will be ignored.
         * if both 'only' and 'except' are empty, then all URLs will be logged.
         * if both 'only' and 'except' are not empty, then only the URLs specified in 'only' will be logged.
         * if 'only' is empty, but 'except' is not empty, then all URLs except the URLs specified in 'except' will be logged.
         * if 'only' is not empty, but 'except' is empty, then only the URLs specified in 'only' will be logged.
         */
        'urls' => [
            'only' => [],
            'except' => [],
        ]
    ],

    'response' => [
        /* Determines whether logging of HTTP responses is enabled. */
        'enabled' => env('LOG_RESPONSE', true),

        /* Title or prefix for response logs. */
        'title' => env('LOG_RESPONSE_TITLE', 'Response'),

        /* Indicates whether information about the authenticated user should be included in the response log. */
        'auth_user' => env('LOG_AUTH_USER_WITH_RESPONSE', true),

        /* Specifies whether the request's unique identifier should be logged with the response. */
        'request_id' => env('LOG_REQUEST_ID_WITH_RESPONSE', true),

        /**
         * Specifying which response data should be logged.
         * if 'only' has data, then 'except' will be ignored.
         * if 'except' has data, then 'only' will be ignored.
         * if both 'only' and 'except' are empty, then all data will be logged.
         * if both 'only' and 'except' are not empty, then only the data specified in 'only' will be logged.
         * if 'only' is empty, but 'except' is not empty, then all data except the data specified in 'except' will be logged.
         * if 'only' is not empty, but 'except' is empty, then only the data specified in 'only' will be logged.
         */
        'data' => [
            'only' => [],
            'except' => [],
        ]
    ],

    'headers' => [
        /* Specifies whether header logging is enabled. */
        'enabled' => env('LOG_HEADERS', true),

        /* Title or prefix for header logs. */
        'title' => env('LOG_HEADERS_TITLE', 'Headers'),

        /* Indicates whether information about the authenticated user should be included in the headers log. */
        'auth_user' => env('LOG_AUTH_USER_IN_HEADERS', true),
    ],

    /* which data of authenticated user to be logged. Default: 'email'. */
    'auth_user_column' => env('LOG_AUTH_USER_COLUMN', 'email'),

    /* which guard of authenticated user to be logged. Default: 'api'. */
    'auth_user_guard' => env('LOG_AUTH_USER_GUARD', 'api'),
];
```

### Testing

[](#testing)

```
composer test
```

### Changelog

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

### Security

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Ayman Alhattami](https://github.com/aymanalhattami)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

Laravel Package Boilerplate
---------------------------

[](#laravel-package-boilerplate)

This package was generated using the [Laravel Package Boilerplate](https://laravelpackageboilerplate.com).

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 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

Every ~0 days

Total

23

Last Release

767d ago

PHP version history (2 changes)0.0.1PHP ^7.4|^8.0|^8.1|^8.2|^8.3

0.0.18PHP ^8.0|^8.1|^8.2|^8.3

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/34315778?v=4)[Ayman Alhattami](/maintainers/aymanalhattami)[@aymanalhattami](https://github.com/aymanalhattami)

---

Top Contributors

[![aymanalhattami](https://avatars.githubusercontent.com/u/34315778?v=4)](https://github.com/aymanalhattami "aymanalhattami (62 commits)")

---

Tags

aymanalhattamilog requestlog request and responselog responselog headerslog methodlog urllog IP address

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/aymanalhattami-log-request-response/health.svg)

```
[![Health](https://phpackages.com/badges/aymanalhattami-log-request-response/health.svg)](https://phpackages.com/packages/aymanalhattami-log-request-response)
```

###  Alternatives

[spatie/laravel-health

Monitor the health of a Laravel application

85810.0M83](/packages/spatie-laravel-health)[beyondcode/laravel-server-timing

Add Server-Timing header information from within your Laravel apps.

5712.0M1](/packages/beyondcode-laravel-server-timing)[rollbar/rollbar-laravel

Rollbar error monitoring integration for Laravel projects

14110.4M7](/packages/rollbar-rollbar-laravel)[yadahan/laravel-authentication-log

Laravel Authentication Log provides authentication logger and notification for Laravel.

416632.8k5](/packages/yadahan-laravel-authentication-log)[kitloong/laravel-app-logger

Laravel log for your application

101.2M8](/packages/kitloong-laravel-app-logger)[label84/laravel-auth-log

Log user authentication actions in Laravel.

3654.0k](/packages/label84-laravel-auth-log)

PHPackages © 2026

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