PHPackages                             touhidurabir/laravel-request-response-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. touhidurabir/laravel-request-response-logger

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

touhidurabir/laravel-request-response-logger
============================================

A PHP laravel package to log the request/response of an app in database in an elegant way with the utilization of Queue and Redis combined

1.0.0(4y ago)23321MITPHPPHP &gt;=7.4

Since Dec 26Pushed 4y ago1 watchersCompare

[ Source](https://github.com/touhidurabir/laravel-request-response-logger)[ Packagist](https://packagist.org/packages/touhidurabir/laravel-request-response-logger)[ RSS](/packages/touhidurabir-laravel-request-response-logger/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (1)Dependencies (4)Versions (2)Used By (0)

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

[](#laravel-request-response-logger)

A PHP laravel package to log the request/response of an app in database in an elegant way with the utilization of Queue and Redis combined .

Why ?
=====

[](#why-)

The first question that with come into anyones' mind is WHY ? There are probably a good number of such package as this one . Also this is not a very diffuclt stuff for anyone to implement into their app . And I do agree with it .

However this package aims to solve one crucial issue that is continious Database write. With the combination of Laravel's excellent Queuing system and Redis list storage , it can handle that case where it put each log data into the redis and then only when a certain limit hits, it will move those data into the DB table in batch which perform a lot less write opetation . It is not required on have the redis or queue must for this package to perform the loggin operation but that is what make this package unique .

For example, lets say you have an app that have one endpoint/route that has need a request/response logging and one average it get hit for like 100/hour . So in traditional way , that just 100 write to DB per hours and that totally acceptable. Now on a high traffic day once or twice a month it get hits 1000 per hours so that 1000 writes to DB which is not too much but still a lot as there are also other read/write from other sections of the app . Using a queue job we can push those DB write task to jobs but thats 1000 jobs per hours which is still a bit unrealistic. But using the Redis list , we can push all those task to redis list and then once a certain limit or time passed , we import those records from redis list to DB through the same job in batch .

This package also contains several handly commands to export data or delete which make use of laravel's LazyCollection and unique appraoch to delete massive amount of data as describe in [Freek's Blog Post](https://flareapp.io/blog/7-how-to-safely-delete-records-in-massive-tables-on-aws-using-laravel)

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

[](#installation)

Require the package using composer:

```
composer require touhidurabir/laravel-request-response-logger
```

To publish the config and migration file:

```
php artisan vendor:publish --provider="Touhidurabir\RequestResponseLogger\RequestResponseLoggerServiceProvider"
```

Next, it's required to run the migration for the new database table. Run the following in your console:

```
php artisan migrate
```

Usage
-----

[](#usage)

### Configure the Options

[](#configure-the-options)

Before using it , please make sure to go throught he pushlished config file to know the available options/settings that you can modify as per your need as this package provide a lot of flexibility.

For example, the ability to push the write task to queue jobs defined by option **`log_on_queue`** and utilize the redis capability defined by option **`store_on_redis`** are set to **`false`** . So depending on your app capabilities and requirements, configure the options as you see fit .

### Setting Up Middleware

[](#setting-up-middleware)

The most important part is is setting up the middleware as all the request/response loggin is done by the provided middleware **`\Touhidurabir\RequestResponseLogger\Middlewares\LogRequestResponse`** by the package .

There are several ways to use the middleare like registering it in the **`/app/Http/Kernel.php`** file and then use it like

Register it as a named middleare and then use it as you like only for the routes where it's needed

```
protected $routeMiddleware = [
    ...
    'requests.responses.logger' => \Touhidurabir\RequestResponseLogger\Middlewares\LogRequestResponse::class,
];

// And then use it for one or more routes
Route::any('/some-route', SomeController::class)->middleware(['requests.responses.logger']);
```

Or register it as route middleware group

```
protected $middlewareGroups = [
    ...
    'api' => [
        \Touhidurabir\RequestResponseLogger\Middlewares\LogRequestResponse::class,
    ],
];
```

Or register it so that by default it apply for every route

```
protected $middleware = [
    ...
    \Touhidurabir\RequestResponseLogger\Middlewares\LogRequestResponse::class,
];
```

Thats it.

> NOTE : It is very unrealistic that this there may be a need to log request/response for every routes of an app, though that depends on the need to application. Register the middleare as per your need and try to avoid it using a global middleare unless that what the app require .

### Register and Run available commands

[](#register-and-run-available-commands)

This package ships with several userful commands . such as

#### Log Cleaner

[](#log-cleaner)

To clear up the logs, use the command **`request-response-logger:clear`** as

```
php artisan request-response-logger:clear
```

Or to set up the cleaning process periodically, register it in **`\App\Console\Kernel`** class's **`schedule`** method as :

```
protected function schedule(Schedule $schedule) {
    ...
    $schedule->command('request-response-logger:clear')->weekly();
}
```

This package also have some handle options available as such :

CommandTypeDescriptionkeep-till-lastvalueKeep the record that has stored in the last given hourslimitvalueNumber of records to delete in per dispatchonly-unmarkedflagDelete only the unmarked recordson-jobflagRun the deletion process through a Queue Job#### Log Exporter

[](#log-exporter)

To export up the logs as CSV and store in storage directory, use the command **`request-response-logger:export`** as

```
php artisan request-response-logger:export
```

Or to set up the exporting process periodically, register it in **`\App\Console\Kernel`** class's **`schedule`** method as :

```
protected function schedule(Schedule $schedule) {
    ...
    $schedule->command('request-response-logger:export')->dailyAt('00:01');
}
```

Unless a specific file name is passed with the option **`--filename`** for this command , it will use the current Datetime as the name of the file .

> NOTE that this package currently only export files in CSV format. Also by default it store the exported CSV files in the **`storage`** dierctory unless provided any other path . See the available command options to know more it

This package also have some handle options available as such :

CommandTypeDescriptionfilenamevalueName of the CSV file to store in storage directorypathvalueThe absolute file store path if decided to store other than storage directoryof-lastvalueExport only last provided hours recordsreplaceflagIf such file exists at given location, replace it with new fileonly-markedflagExport only marked recordswith-trashedflagExport records along with soft deleted entries#### Redis List Storage Importer

[](#redis-list-storage-importer)

This is one unique command only applicable if you utilize the redis list storage with this package . What is does that it will import whatever logs that has been stored in the redis (through the specified key of config) into the DB table . Handy if you need to import all the records stored in redis list right away and dont want to wait till it hit the **`max_redis_count`** specificed in the config file .

Run the command as :

```
php artisan request-response-logger:redis-import
```

Or to set up the importing process periodically, register it in **`\App\Console\Kernel`** class's **`schedule`** method as :

```
protected function schedule(Schedule $schedule) {
    ...
    $schedule->command('request-response-logger:redis-import')->hourly();
}
```

### Model

[](#model)

If you would like to work with the data you've logged, you may want to retrieve data based on the http code . Or you may want to mark some records based on some logic which needed to be presist for a longer time . To Do such stuff , use the mode defined in the config file's **`model`** option . By default it will use the **`\Touhidurabir\RequestResponseLogger\Models\RequestResponseLogger::class`** model class .

Also the default model provide some handle methods/scopes to work with such as :

```
use Touhidurabir\RequestResponseLogger\Models\RequestResponseLogger;

// Get every logged item with an http response code of 2xx:
RequestResponseLogger::successful()->get();

// Get every logged item with an http response code that ISN'T 2xx:
RequestResponseLogger::failed()->get();

// Get every logged item which are marked
RequestResponseLogger::marked()->get();
```

This package also keep track if request are coming from logged in user and make the user data to log data association . So it's possible to find for which user is request log has registered as :

```
RequestResponseLogger::with(['user'])->get();
```

If you need more methods , just extends the default model class or create your own and register it in the published config file .

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

[](#contributing)

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License
-------

[](#license)

[MIT](./LICENSE.md)

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity49

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

Unknown

Total

1

Last Release

1599d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/6c6009d764c48df4a55a8645c349f90a99c7e6e694b06c60b580e1da278d1db5?d=identicon)[touhidurabir](/maintainers/touhidurabir)

---

Top Contributors

[![touhidurabir](https://avatars.githubusercontent.com/u/2587979?v=4)](https://github.com/touhidurabir "touhidurabir (12 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/touhidurabir-laravel-request-response-logger/health.svg)

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

###  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)
