PHPackages                             jrebs/laravel-log-requests - 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. jrebs/laravel-log-requests

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

jrebs/laravel-log-requests
==========================

Log requests and responses with minimal effort.

017PHP

Since Apr 21Pushed 5y ago1 watchersCompare

[ Source](https://github.com/jrebs/laravel-log-requests)[ Packagist](https://packagist.org/packages/jrebs/laravel-log-requests)[ RSS](/packages/jrebs-laravel-log-requests/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependenciesVersions (2)Used By (0)

laravel-log-requests
====================

[](#laravel-log-requests)

A quick and easy drop-in Laravel package to add simple logging of http requests and responses. No configuration required beyond associating the provided middleware with the routes you want to include.

I created this package with the following in mind:

- capture the request &amp; response of API calls to the app
- leverage latest Laravel features allowing effortless package injection
- easily re-usable across apps with a sensible zero-config default
- allow easily overriding the handler for app or env customizations

requirements
------------

[](#requirements)

- `php >= 7.2`
- `laravel/framework >= 5.8`

install
-------

[](#install)

```
composer require jrebs/laravel-log-requests
```

To use defaults, publish the migration to your application and migrate:

```
php artisan vendor:publish --provider=Jrebs\\LogRequests\\Providers\\LogRequestsServiceProvider

php artisan migrate
```

Now you just need to declare routes to be logged. Your `App\Http\Kernel` may then contain something like this:

```
protected $middlewareGroups = [
    // ...
    'api' => [
        'throttle:60,1',
        'bindings',
        'log-requests', // Record all API requests to api_requests table
    ],
];
```

Now when you hit routes covered by `api`, you should find them being stored and can be accessed with the `Jrebs\LogRequests\LoggedRequest` model.

Alternately, you can apply the middleware in a routes file:

```
// routes/web.php
Route::middleware('log-requests')->group(function () {
    // routes defined in this group closure will all be passed to the handler
});
```

Accessing Logs
--------------

[](#accessing-logs)

The default log handler uses the provided `Jrebs\LogRequests\LoggedRequest`. I recommend that if you're going to write any code to access the provided log models, you should extend the `LoggedRequest` class to something in your `App` namespace and then you can set up relationships on the model, such as joining the `user_id` property against your `App\User` model or similar.

Example Custom Handler
----------------------

[](#example-custom-handler)

To use your own storage method, skip publishing migrations and instead only publish `config` so you can provide your own handler:

```
php artisan vendor:publish --provider=Jrebs\\LogRequests\\Providers\\LogRequestsServiceProvider --tag=config
```

Now you need to declare your custom handler in `config/log-requests.php`:

```
return [
    // Set an app-provided Handler to override the package handler
    'handler' => env('LOG_REQUESTS_HANDLER', App\CustomHandler::class),
];
```

As you can see, it is also possible to override this setting at runtime by editing your `.env` file with similar:

```
# Override both the package and the app-provided handler
LOG_REQUESTS_HANDLER=App\CustomHandler
```

A custom handler needs to implement the `LogRequestsHandler` interface, providing a static `log()` method accepting request, response and duration. This is a simplistic example of how you might provide your own custom handler in `app/CustomHandler.php`

```
/**
 * Example handler - app/CustomHandler.php
 */
namespace App;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;
use Jrebs\LogRequests\LogRequestsHandler;

class CustomHandler implements LogRequestHandler
{
    public static function log($request, $response, $duration): void
    {
        /**
         * @param  \Illuminate\Http\Request  $request
         * @param  \Illuminate\Http\Response  $response
         * @param  float  $duration
         */
        Log::debug(sprintf(
            "Request: %s\nResponse: %s\nDuration: %s",
            serialize($request->input()),
            serialize($response->getContent()),
            $duration
        ));
    }
}
```

todo
----

[](#todo)

- write a todo list
- figure out if there's some sensible way to test the package standalone

###  Health Score

17

—

LowBetter than 6% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity32

Early-stage or recently created project

 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/7be6aa129cd8860ec177bd2820612c277dd9a80c904a8e814c46fdccdca2e6fa?d=identicon)[jrebs](/maintainers/jrebs)

---

Top Contributors

[![jrebs](https://avatars.githubusercontent.com/u/4203789?v=4)](https://github.com/jrebs "jrebs (9 commits)")

### Embed Badge

![Health badge](/badges/jrebs-laravel-log-requests/health.svg)

```
[![Health](https://phpackages.com/badges/jrebs-laravel-log-requests/health.svg)](https://phpackages.com/packages/jrebs-laravel-log-requests)
```

###  Alternatives

[psr/log

Common interface for logging libraries

10.4k1.2B9.2k](/packages/psr-log)[itsgoingd/clockwork

php dev tools in your browser

5.9k27.6M94](/packages/itsgoingd-clockwork)[graylog2/gelf-php

A php implementation to send log-messages to a GELF compatible backend like Graylog2.

41838.2M138](/packages/graylog2-gelf-php)[bugsnag/bugsnag-psr-logger

Official Bugsnag PHP PSR Logger.

32132.5M2](/packages/bugsnag-bugsnag-psr-logger)[consolidation/log

Improved Psr-3 / Psr\\Log logger based on Symfony Console components.

15462.2M7](/packages/consolidation-log)[datadog/php-datadogstatsd

An extremely simple PHP datadogstatsd client

19124.6M15](/packages/datadog-php-datadogstatsd)

PHPackages © 2026

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