PHPackages                             vinothkumar/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. vinothkumar/request-logger

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

vinothkumar/request-logger
==========================

A laravel package to track request flow

00PHP

Since May 22Pushed 12mo ago1 watchersCompare

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

READMEChangelogDependenciesVersions (2)Used By (0)

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

[](#laravel-request-logger)

`vinothkumar/request-logger` is a Laravel package designed to simplify request tracing and debugging by automatically injecting a unique Request ID into every log entry generated during a request's lifecycle. This allows for easier tracking of a request's journey through various parts of your application, including controllers, services, jobs, and more.

🚀 Features
----------

[](#-features)

- **Automatic Request ID Injection:** Seamlessly adds a unique ID to each incoming request.
- **Integrated Logging:** Automatically appends the `request_id` to all log entries made using Laravel's default logging system.
- **Configurable Header:** Allows customization of the HTTP header name used for the request ID (default: `X-Request-Id`).
- **Configurable Attribute Key:** Enables setting a custom key for accessing the request ID on the Request object and via the application container (default: `request_id`).
- **Laravel Compatibility:** Supports Laravel versions 10 and 11.
- **Auto-Discovery:** Service provider is auto-discovered by Laravel.
- **Middleware Based:** Uses middleware to manage the request ID lifecycle.

📦 Installation
--------------

[](#-installation)

Install the package into your Laravel project using Composer:

```
composer require vinothkumar/request-logger
```

⚙️ Configuration
----------------

[](#️-configuration)

The package's service provider is automatically registered thanks to Laravel's auto-discovery feature.

To customize the default settings, you can publish the configuration file:

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

This will create a `config/request-logger.php` file in your application. The available options are:

- `header_name` (string):

    - Defines the name of the HTTP header used to carry the request ID. If an incoming request includes this header, its value will be used as the request ID; otherwise, a new ID will be generated. This header is also added to outgoing responses.
    - Default: `'X-Request-Id'`
- `request_attribute_key` (string):

    - Defines the key under which the request ID is stored as an attribute on the Laravel `Request` object (`$request->attributes`). It's also used as the binding key for the request ID instance in the service container (`app(...)`).
    - Default: `'request_id'`

🔗 Middleware Registration
-------------------------

[](#-middleware-registration)

The `RequestIdMiddleware` is responsible for identifying or generating the request ID and making it available to your application. You need to register this middleware manually.

For global usage (recommended for most applications), add it to the `$middleware` property in your `app/Http/Kernel.php` file:

```
// app/Http/Kernel.php

protected $middleware = [
    // ... other global middleware
    \Vinothkumar\RequestLogger\Http\Middleware\RequestIdMiddleware::class,
    // ... other global middleware
];
```

Alternatively, you can register it for specific routes or route groups if you only need request ID logging for certain parts of your application.

🛠️ How it Works / Usage
-----------------------

[](#️-how-it-works--usage)

Once the package is installed, configured, and the middleware is registered, it works automatically.

1. The `RequestIdMiddleware` inspects incoming requests:
    - If the configured header (e.g., `X-Request-Id`) is present, its value is used as the request ID.
    - If the header is not present, a new UUID v4 is generated to serve as the request ID.
2. The request ID is then:
    - Set as an attribute on the current `Request` object, accessible via `$request->attributes->get('your_configured_key')`.
    - Bound to the service container, accessible via `app('your_configured_key')`.
    - Added to the response headers for outgoing responses.
3. The `AddRequestIdProcessor` (automatically registered with your default logger) then appends this request ID to every log entry made through Laravel's `Log` facade or logger instance.

**Example Log Entry:**

When you use `Log::info('This is a log message.');` or similar, the output in your log file will look something like this (assuming default configuration):

```
[2023-10-27 10:00:00] local.INFO: This is a log message. {"extra":{"request_id":"your-unique-request-id"}}

```

You can also access the request ID directly within your application code after the middleware has run:

```
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;

// In a controller method
public function someAction(Request $request)
{
    $requestIdFromAttribute = $request->attributes->get(config('request-logger.request_attribute_key'));
    $requestIdFromApp = app(config('request-logger.request_attribute_key'));

    Log::info('Current request ID from attribute: ' . $requestIdFromAttribute);
    // ... your logic
}
```

🧪 Testing
---------

[](#-testing)

The package includes a suite of unit tests to ensure its functionality. If you've cloned the repository locally, you can run the tests using:

```
composer test
```

(This assumes you have a "test" script defined in your `composer.json`, like `"test": "vendor/bin/phpunit"` or similar.)

📄 License
---------

[](#-license)

This package is open-source software licensed under the The MIT License (MIT). Please see the [LICENSE](LICENSE) file for more information. (Note: A `LICENSE` file should be present in the repository root.)

###  Health Score

15

—

LowBetter than 3% of packages

Maintenance37

Infrequent updates — may be unmaintained

Popularity0

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity16

Early-stage or recently created project

 Bus Factor1

Top contributor holds 50% 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/462c1a7f382c258fd92ce89e566fe1d80974d1fffb41fc453b8dffd4a2ec8a71?d=identicon)[vinothkumar95](/maintainers/vinothkumar95)

---

Top Contributors

[![google-labs-jules[bot]](https://avatars.githubusercontent.com/in/842251?v=4)](https://github.com/google-labs-jules[bot] "google-labs-jules[bot] (2 commits)")[![vinothkumar95](https://avatars.githubusercontent.com/u/120662401?v=4)](https://github.com/vinothkumar95 "vinothkumar95 (2 commits)")

### Embed Badge

![Health badge](/badges/vinothkumar-request-logger/health.svg)

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

###  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)[ekino/newrelic-bundle

Integrate New Relic into Symfony2

28111.2M8](/packages/ekino-newrelic-bundle)

PHPackages © 2026

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