PHPackages                             befuturein/laravel-log-enhancer - 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. befuturein/laravel-log-enhancer

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

befuturein/laravel-log-enhancer
===============================

A lightweight Laravel package that enriches your logs with structured request, user, and application context.

v1.0.0(5mo ago)00MITPHPPHP ^8.1CI passing

Since Nov 29Pushed 5mo agoCompare

[ Source](https://github.com/befuturein/laravel-log-enhancer)[ Packagist](https://packagist.org/packages/befuturein/laravel-log-enhancer)[ RSS](/packages/befuturein-laravel-log-enhancer/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (6)Versions (2)Used By (0)

Laravel Log Enhancer
====================

[](#laravel-log-enhancer)

[![Latest Version on Packagist](https://camo.githubusercontent.com/541af6aa4a93389f27aad145eec4f1cd9bef23f099cf86196bbb4218debf78c5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6265667574757265696e2f6c61726176656c2d6c6f672d656e68616e6365722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/befuturein/laravel-log-enhancer)[![Total Downloads](https://camo.githubusercontent.com/384d040d95c7fc7af1d310d024bd60d6149f8ab509229465ab3119fcc944be89/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6265667574757265696e2f6c61726176656c2d6c6f672d656e68616e6365722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/befuturein/laravel-log-enhancer)[![GitHub Tests](https://github.com/befuturein/laravel-log-enhancer/actions/workflows/tests.yml/badge.svg)](https://github.com/befuturein/laravel-log-enhancer/actions/workflows/tests.yml)[![License](https://camo.githubusercontent.com/15598ba0fcc49b837b43062e9abf054fe42cd7260e77b271b353ea7d92c38a77/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6265667574757265696e2f6c61726176656c2d6c6f672d656e68616e6365722e7376673f7374796c653d666c61742d737175617265)](LICENSE)

A lightweight, framework-friendly Laravel package that enriches your logs with structured context such as request data, authenticated user information, correlation IDs, and application metadata.

This package is designed to be:

- **Non-intrusive** – opt-in via configuration and logging taps.
- **Framework-friendly** – built for Laravel 10+ and 11.
- **Production-ready** – focuses on predictable, structured context and safe redaction.

Features
--------

[](#features)

- Adds a correlation ID to every HTTP request (header or generated).
- Provides a `ContextResolver` that builds a consistent context array.
- Optional Laravel logging tap (`ContextTap`) to push context into Monolog records.
- Simple `LogEnhancer` facade helper for manually merging context into log calls.
- Configurable redaction for sensitive keys (e.g. `password`, `token`).
- Minimal dependencies, focused only on request and authentication context.

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

[](#installation)

Install the package via Composer:

```
composer require befuturein/laravel-log-enhancer
```

> The package uses Laravel's automatic package discovery. No manual registration is required.

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

[](#configuration)

Publish the configuration file:

```
php artisan vendor:publish --provider="BeFuture\LogEnhancer\LogEnhancerServiceProvider" --tag="log-enhancer-config"
```

This will create a `config/log-enhancer.php` file. The default options look like this (simplified):

```
return [
    'enabled' => true,
    'correlation' => [
        'header' => 'X-Correlation-Id',
    ],
    'context' => [
        'include_request' => true,
        'include_user' => true,
        'include_app' => true,
    ],
    'redact' => [
        'keys' => ['password', 'password_confirmation', 'token'],
        'mask' => '***',
    ],
];
```

Adjust these options according to your security and observability requirements.

HTTP Middleware
---------------

[](#http-middleware)

The package ships with a middleware that ensures each request has a correlation ID.

Register the middleware in your HTTP kernel (or route group):

```
use BeFuture\LogEnhancer\Middleware\InjectLogContext;

protected $middleware = [
    // ...
    InjectLogContext::class,
];
```

Or in a specific group:

```
protected $middlewareGroups = [
    'web' => [
        // ...
        \BeFuture\LogEnhancer\Middleware\InjectLogContext::class,
    ],
];
```

Logging Tap (Automatic Context Injection)
-----------------------------------------

[](#logging-tap-automatic-context-injection)

To automatically inject context into a specific log channel, register the tap class in your `config/logging.php`:

```
'channels' => [
    'stack' => [
        'driver' => 'stack',
        'channels' => ['single'],
        'tap' => [
            \BeFuture\LogEnhancer\Logging\ContextTap::class,
        ],
    ],
],
```

The `ContextTap` will push a Monolog processor that merges the resolved context into the `extra` payload of each log record.

Manual Usage via Facade
-----------------------

[](#manual-usage-via-facade)

You can also manually merge context into your logs using the `LogEnhancer` facade:

```
use Illuminate\Support\Facades\Log;
use BeFuture\LogEnhancer\Facades\LogEnhancer;

Log::info('User updated profile', LogEnhancer::context([
    'custom_note' => 'profile_update',
]));
```

The `context()` method will merge:

- Request metadata (method, path, IP, user agent, correlation ID).
- Authenticated user data (ID, type, and optionally email/name if available).
- Application metadata (environment, app name).

Any keys configured in the `redact.keys` setting will be masked.

Testing
-------

[](#testing)

The package includes a basic test suite powered by [orchestra/testbench](https://github.com/orchestral/testbench).

Run tests with:

```
composer test
```

or directly via PHPUnit:

```
./vendor/bin/phpunit
```

Coding Style
------------

[](#coding-style)

This repository ships with a [Laravel Pint](https://github.com/laravel/pint) configuration:

```
./vendor/bin/pint
```

CI / GitHub Actions
-------------------

[](#ci--github-actions)

A sample GitHub Actions workflow is provided under `.github/workflows/tests.yml`. It runs:

- Installation with Composer.
- Static analysis via `php -l` (syntax check).
- PHPUnit test suite.
- Laravel Pint for code style.

You can adjust or extend this workflow based on your project needs.

License
-------

[](#license)

This package is open-sourced software licensed under the [MIT license](LICENSE).

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance71

Regular maintenance activity

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity43

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

164d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/e86dad672c575acf9b65cfea8ecc8804d82943b0753e257e4b881e1a19f8d481?d=identicon)[muratcankayalak](/maintainers/muratcankayalak)

---

Top Contributors

[![muratcankayalak](https://avatars.githubusercontent.com/u/19274136?v=4)](https://github.com/muratcankayalak "muratcankayalak (6 commits)")

---

Tags

loglaravelloggingmonitoringContextobservability

###  Code Quality

TestsPHPUnit

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/befuturein-laravel-log-enhancer/health.svg)

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

###  Alternatives

[yadahan/laravel-authentication-log

Laravel Authentication Log provides authentication logger and notification for Laravel.

416632.8k5](/packages/yadahan-laravel-authentication-log)[ytake/laravel-fluent-logger

fluent logger for laravel and lumen

63541.6k1](/packages/ytake-laravel-fluent-logger)[dragon-code/laravel-http-logger

Logging incoming HTTP requests

319.8k3](/packages/dragon-code-laravel-http-logger)[shaffe/laravel-mail-log-channel

A package to support logging via email in Laravel

1286.2k](/packages/shaffe-laravel-mail-log-channel)[melihovv/laravel-log-viewer

A Laravel log viewer

1231.5k1](/packages/melihovv-laravel-log-viewer)

PHPackages © 2026

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