PHPackages                             andriichuk/laravel-http-client-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. [HTTP &amp; Networking](/categories/http)
4. /
5. andriichuk/laravel-http-client-logger

ActiveLibrary[HTTP &amp; Networking](/categories/http)

andriichuk/laravel-http-client-logger
=====================================

Configurable request/response logger for Laravel HTTP client with sanitization and status filters

0.2.2(1mo ago)05—0%[1 PRs](https://github.com/andriichuk/laravel-http-client-logger/pulls)MITPHPPHP ^8.3CI passing

Since Mar 14Pushed 1mo agoCompare

[ Source](https://github.com/andriichuk/laravel-http-client-logger)[ Packagist](https://packagist.org/packages/andriichuk/laravel-http-client-logger)[ Docs](https://github.com/andriichuk/laravel-http-client-logger)[ GitHub Sponsors](https://github.com/andriichuk)[ RSS](/packages/andriichuk-laravel-http-client-logger/feed)WikiDiscussions main Synced 1mo ago

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

Laravel HTTP Client Logger
==========================

[](#laravel-http-client-logger)

[![Latest Version on Packagist](https://camo.githubusercontent.com/a7976817bc265b3a3ea5a20d5df09fe9a6ffd45ec6269affe7e58be3353db1cf/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f616e647269696368756b2f6c61726176656c2d687474702d636c69656e742d6c6f676765722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/andriichuk/laravel-http-client-logger)[![GitHub Tests Action Status](https://camo.githubusercontent.com/ee0c54726c4f1618bdaeafdd28a94ce934ae0d684cce5ddcbfa17424205eb2e4/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f616e647269696368756b2f6c61726176656c2d687474702d636c69656e742d6c6f676765722f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/andriichuk/laravel-http-client-logger/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/0631ff849f353abdeaf0b27477bdef59fd28bf54943f616cd1bc4dcd94338aba/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f616e647269696368756b2f6c61726176656c2d687474702d636c69656e742d6c6f676765722f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/andriichuk/laravel-http-client-logger/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/b809ce337f1f9acf396c2f061f1bd399fe1067a57a08736d76785cd5a06c65f7/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f616e647269696368756b2f6c61726176656c2d687474702d636c69656e742d6c6f676765722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/andriichuk/laravel-http-client-logger)

A **super simple**, configurable logger for Laravel’s HTTP client (outgoing requests). Ideal for APIs and third-party integrations.

- **Sanitization** — Mask sensitive fields and headers (e.g. password, authorization).
- **Filters** — Limit by response status (2xx, 4xx, 5xx, etc.).
- **Headers** — Choose which request/response headers to include in logs. Use `['*']` for all; when the arrays are empty, no header keys are added to the log at all.
- **Optional response body** — Include decoded, sanitized response body (JSON); non-JSON can be truncated or skipped.
- **Request files (multipart)** — When sending files via `attach()`, log metadata (name, original\_name, size, mime\_type, extension) in context as `uploaded_files`; no file contents are logged. Aligns with [laravel-http-logger](https://github.com/andriichuk/laravel-http-logger).

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

[](#installation)

**Requirements:** PHP 8.2+ and Laravel 10.x, 11.x or 12.x.

Install the package via Composer:

```
composer require andriichuk/laravel-http-client-logger
```

Publish the config file:

```
php artisan vendor:publish --tag="http-client-logger-config"
```

(Optional) Add a dedicated log channel for HTTP client logs in `config/logging.php` (e.g. a separate file or stack). If you skip this, the package uses your default log channel.

```
'channels' => [
    // ...
    'http_client' => [
        'driver' => 'daily',
        'path' => storage_path('logs/http_client.log'),
        'level' => 'debug',
    ],
],
```

> **Important — when is logging on?** If `LOG_HTTP_CLIENT_REQUESTS` is not set in `.env`, the logger follows **`APP_DEBUG`**: it is enabled when `APP_DEBUG=true` (e.g. local) and disabled when `APP_DEBUG=false` (e.g. production). To force it on or off, set **`LOG_HTTP_CLIENT_REQUESTS=true`** or **`LOG_HTTP_CLIENT_REQUESTS=false`** in your `.env`, or set `'enabled'` in `config/http-client-logger.php`. The log channel can be overridden with **`HTTP_CLIENT_LOG_CHANNEL`** (e.g. `HTTP_CLIENT_LOG_CHANNEL=http_client` to use the channel above).

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

[](#configuration)

After publishing, configure `config/http-client-logger.php` as needed.

KeyDescriptionDefault`enabled`Master switch for HTTP client logging. When `LOG_HTTP_CLIENT_REQUESTS` is unset, falls back to `APP_DEBUG`. When disabled, the `log` macro still exists but no entries are written.`env('LOG_HTTP_CLIENT_REQUESTS', APP_DEBUG)``channel`Log channel name (must exist in `config/logging.php`).`HTTP_CLIENT_LOG_CHANNEL` or `LOG_CHANNEL` or `'stack'``report`Which response status categories to log: `info` (1xx), `success` (2xx), `redirect` (3xx), `client_error` (4xx), `server_error` (5xx). Each key is a boolean.`info`/`success` → `false`; `redirect`/`client_error`/`server_error` → `true``log_level_by_status`Map each status category to a PSR log level (`debug`, `info`, `notice`, `warning`, `error`, etc.). 5xx → `error` and 4xx → `warning` by default for easier filtering.`client_error` → `warning`; `server_error` → `error`; others → `info``include_response`Include response body in log context.`true``include_non_json_response`When `include_response` is true, include non-JSON bodies (HTML, text, etc.) in the log (truncated). Set to `true` to include them; default logs as `'[skipped]'`.`false``include_request_headers`Request header names (lowercase) to include. Use `['*']` for all. When empty, no request headers are added to the log.`['*']``include_response_headers`Response header names (lowercase) to include. Use `['*']` for all. When empty, no response headers are added to the log.`['*']``include_uploaded_files_metadata`When true, multipart requests that send files (e.g. via `attach()`) include file metadata in log context as `uploaded_files`: name, original\_name, size, mime\_type, extension, error. No file contents are logged.`true``sensitive_fields`Request/response body keys to replace with `***`.`['token', 'refresh_token', 'password', …]``sensitive_headers`Header names (lowercase) to replace with `***`.`['authorization', 'cookie']``max_string_value_length`Max length for string values in bodies (and non-JSON response body) before truncation. Use `null` to disable truncation.`100``message_prefix`Prefix for the log message.`'[HttpClientLogger] '`**Response body logging:** JSON responses are decoded and sanitized; `max_string_value_length` applies to each string value. Non-JSON responses are logged as a truncated string or `'[skipped]'`. The log **level** follows response status by default (5xx → `error`, 4xx → `warning`, 1xx/2xx/3xx → `info`); configure via `log_level_by_status`.

Usage
-----

[](#usage)

Use the `log` macro on the Laravel HTTP client to log that request and its response (or failure).

**Basic:**

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

Http::log()->get('https://api.example.com/users');
Http::log()->post('https://api.example.com/orders', ['item' => 'widget']);
```

**With context (e.g. name in the log message):**

```
Http::log(['name' => 'Stripe'])->post('https://api.stripe.com/v1/charges', $payload);
```

**Using the `name` macro:**

Use the `name` macro to add a `name` key to the logging context and include it in the log message. Handy for chaining and identifying which integration a request belongs to.

```
Http::name('Stripe')->log()->get('https://api.stripe.com/v1/balance');
```

The name appears in the log message right after the prefix (e.g. `[HttpClientLogger] Stripe GET https://api.stripe.com/v1/balance`).

**Sending files (multipart):**

When you send files with `attach()`, the logger can include file metadata in the log context as `uploaded_files` (name, original\_name, size, mime\_type, extension). No file contents are logged. Enable or disable via `include_uploaded_files_metadata` in config.

```
Http::log()->attach('document', $fileContents, 'report.pdf')->post('https://api.example.com/upload');
// or with Laravel's UploadedFile:
Http::log()->attach('avatar', $request->file('avatar'))->post('https://api.example.com/profile/photo');
```

When `enabled` is `false` in config, the macro is still available but the middleware does not write any log entries.

Callbacks
---------

[](#callbacks)

You can register one or more callbacks that run when a request is logged (after the same checks that allow logging: `enabled`, and for success responses, the status filter). Use this to push metrics, notify, or run custom logic whenever an outgoing request is logged.

**Callback signature:** `(RequestInterface $request, ?ResponseInterface $response, float $executionTimeMs): void`

- On **success** (in `logSuccess`), `$response` is the PSR-7 response.
- On **exception** (in `logException`), `$response` is `null`.

Register callbacks in your `AppServiceProvider::boot()` method using the `HttpClientLogger` facade:

```
use Andriichuk\HttpClientLogger\HttpClientLogger;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;

public function boot(): void
{
    HttpClientLogger::addCallback(function (RequestInterface $request, ?ResponseInterface $response, float $executionTimeMs): void {
        // $response is null when the request failed (exception path)
        // Runs only when logging is enabled and (for success) status is reported
    });
}
```

Callbacks are invoked before the package writes to the log context. If a callback throws, the exception is not caught by the package and bubbles up to the caller.

Example log output
------------------

[](#example-log-output)

**Successful API call (200):** `INFO` level, with name and sanitized response.

```
[2026-03-14 10:15:22] local.INFO: [HttpClientLogger] Stripe GET https://api.stripe.com/v1/balance {"response_status_code":200,"request_headers":{"content-type":["application/json"],"authorization":"***"},"response_headers":{"content-type":["application/json"]},"request_body":[],"response_body":{"available":[{"amount":1000,"currency":"usd"}],"token":"***"},"execution_time_ms":142}

```

**Client error (422):** `WARNING` level, authorization masked, JSON response with validation errors.

```
[2026-03-14 10:16:01] local.WARNING: [HttpClientLogger] POST https://api.example.com/orders {"response_status_code":422,"request_headers":{"content-type":["application/json"],"authorization":"***"},"response_headers":[],"request_body":{"item":"widget","quantity":-1},"response_body":{"message":"The quantity must be at least 1.","errors":{"quantity":["The quantity must be at least 1."]}},"execution_time_ms":89}

```

**Message (no name):** `[HttpClientLogger] GET https://api.example.com/users`

**Multipart with file:** `uploaded_files` in context (metadata only; no file contents).

```
[2026-03-14 10:20:00] local.INFO: [HttpClientLogger] POST https://api.example.com/upload {"response_status_code":200,"request_headers":{...},"response_headers":{},"request_body":"...","response_body":"...","execution_time_ms":45,"uploaded_files":[{"name":"document","original_name":"report.pdf","size":null,"mime_type":null,"extension":"pdf","error":0}]}

```

Testing
-------

[](#testing)

Run the test suite with Pest:

```
composer test
```

Changelog
---------

[](#changelog)

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

License
-------

[](#license)

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

Credits
-------

[](#credits)

- [Serhii Andriichuk](https://github.com/andriichuk)
- [All Contributors](https://github.com/andriichuk/laravel-http-client-logger/contributors)

###  Health Score

38

—

LowBetter than 85% of packages

Maintenance90

Actively maintained with recent releases

Popularity5

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity42

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 ~2 days

Total

5

Last Release

52d ago

PHP version history (2 changes)0.1.0PHP ^8.4

0.1.1PHP ^8.3

### Community

Maintainers

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

---

Top Contributors

[![andriichuk](https://avatars.githubusercontent.com/u/38154251?v=4)](https://github.com/andriichuk "andriichuk (25 commits)")

---

Tags

httpresponserequestmiddlewareapilaravellogginghttp clientGuzzle

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/andriichuk-laravel-http-client-logger/health.svg)

```
[![Health](https://phpackages.com/badges/andriichuk-laravel-http-client-logger/health.svg)](https://phpackages.com/packages/andriichuk-laravel-http-client-logger)
```

###  Alternatives

[aplus/http-client

Aplus Framework HTTP Client Library

2161.6M1](/packages/aplus-http-client)[bilfeldt/laravel-http-client-logger

A logger for the Laravel HTTP Client

1531.6M3](/packages/bilfeldt-laravel-http-client-logger)[hamburgscleanest/guzzle-advanced-throttle

A Guzzle middleware that can throttle requests according to (multiple) defined rules. It is also possible to define a caching strategy, e.g. get response from cache when rate limit is exceeded or always get cached value to spare your rate limits.

13033.4k1](/packages/hamburgscleanest-guzzle-advanced-throttle)[onlime/laravel-http-client-global-logger

A global logger for the Laravel HTTP Client

1935.1k](/packages/onlime-laravel-http-client-global-logger)[hamburgscleanest/laravel-guzzle-throttle

A Laravel wrapper for https://github.com/hamburgscleanest/guzzle-advanced-throttle.

7914.3k](/packages/hamburgscleanest-laravel-guzzle-throttle)[dragon-code/laravel-http-logger

Logging incoming HTTP requests

319.8k3](/packages/dragon-code-laravel-http-logger)

PHPackages © 2026

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