PHPackages                             solitus0/httplug-logger-plugin - 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. solitus0/httplug-logger-plugin

ActiveSymfony-bundle[Logging &amp; Monitoring](/categories/logging)

solitus0/httplug-logger-plugin
==============================

v0.1.0(6mo ago)01MITPHPPHP &gt;=8.1CI passing

Since Dec 23Pushed 6mo agoCompare

[ Source](https://github.com/solitus0/httplug-logger-plugin)[ Packagist](https://packagist.org/packages/solitus0/httplug-logger-plugin)[ RSS](/packages/solitus0-httplug-logger-plugin/feed)WikiDiscussions 0.1.x Synced today

READMEChangelog (1)Dependencies (14)Versions (3)Used By (0)

httplug-logger-plugin
=====================

[](#httplug-logger-plugin)

Symfony bundle that logs HTTPlug requests/responses through Monolog, with optional Guzzle transfer stats and Google Cloud log formatting.

Features
--------

[](#features)

- HTTPlug plugin that logs request + response context for each client.
- Structured context (`httpRequest`, `jsonPayload`, `transfer_stats`) suitable for JSON logging.
- Log level selection based on response status (2xx info, 4xx warning, 500 error, &gt;500 critical).
- Optional Guzzle transfer stats (latency + timing breakdown).
- Optional request/trace decorators for Google Cloud logging.

Requirements
------------

[](#requirements)

- PHP 8.1+
- Symfony 6.4+
- Monolog 3.7+
- HTTPlug (php-http/client-common)
- Guzzle 7 adapter (for transfer stats factory)

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

[](#installation)

```
composer require solitus0/httplug-logger-plugin
```

If you are not using Symfony Flex, register the bundle:

```
return [
    Solitus0\HttplugLoggerBundle\LoggerBundle::class => ['all' => true],
];
```

Basic Configuration
-------------------

[](#basic-configuration)

Define one or more logging plugins:

```
# config/packages/httplug_logger.yaml
httplug_logger:
    plugins:
        api_client:
            parser_collection: httplug_logger.parser_collection.default
            level_picker: httplug_logger.level_picker.default
            logger: monolog.logger.http_client
```

Attach the plugin to an HTTPlug client:

```
# config/packages/httplug.yaml
httplug:
    clients:
        api_client:
            plugins:
                - httplug_logger.plugin.api_client
```

Transfer Stats (Guzzle 7)
-------------------------

[](#transfer-stats-guzzle-7)

To log transfer timing metrics, use the provided factory (it injects Guzzle `on_stats` to collect timing data):

```
# config/packages/httplug.yaml
httplug:
    clients:
        api_client:
            factory: httplug_logger.guzzle7_factory.transfer_stats_aware
            plugins:
                - httplug_logger.plugin.api_client
```

When enabled, the log context includes:

- `transfer_stats`: `namelookup_time`, `connect_time`, `appconnect_time`, `pretransfer_time`, `starttransfer_time`, `total_time` (seconds)
- `httpRequest.latency`: formatted string like `0.123456s`

Monolog Formatter (Google Cloud Logging)
----------------------------------------

[](#monolog-formatter-google-cloud-logging)

The bundle provides a JSON formatter that reshapes records to Google Cloud Logging format:

```
# config/packages/monolog.yaml
monolog:
    handlers:
        http_client:
            type: stream
            path: "php://stdout"
            formatter: monolog.formatter.gcp
            level: info
```

Optional Log Decorators
-----------------------

[](#optional-log-decorators)

Configure decorators that add extra metadata to logs:

```
# config/packages/httplug_logger.yaml
httplug_logger:
    features:
        request_decorator: true
        gcp_trace_decorator: false
```

- `request_decorator` adds `referer`, `route`, `remoteIp`, `host`, `userAgent` to the log record `extra`.
- `gcp_trace_decorator` reads the `x-cloud-trace-context` header and adds a `logging.googleapis.com/trace` value. It requires `GOOGLE_CLOUD_PROJECT_ID` in your environment.

Response Payload Truncation
---------------------------

[](#response-payload-truncation)

Response payload logging is enabled by default and truncated if it exceeds a size limit:

```
# config/packages/httplug_logger.yaml
httplug_logger:
    parser:
        response_payload_truncate: true
        response_payload_max_kilobyte_size: 7
```

Notes:

- If a response has a `content-disposition` header (e.g., file download), the payload is replaced with a placeholder message.
- JSON responses are decoded and logged as structured data when possible.

GraphQL Request Payloads
------------------------

[](#graphql-request-payloads)

A GraphQL request payload parser exists but is not part of the default parser collection. To enable it, define a custom parser collection service:

```
# config/services.yaml
services:
    httplug_logger.parser_collection.graphql:
        class: Solitus0\HttplugLoggerBundle\Parser\PsrHttpMessageParserCollection
        autowire: true
        autoconfigure: true
        arguments:
            $parsers:
                - '@httplug_logger.parser.psr_request'
                - '@httplug_logger.parser.psr_request_graphql_payload'
                - '@httplug_logger.parser.psr_response'
                - '@httplug_logger.parser.psr_response_payload'
                - '@httplug_logger.parser.exception'
                - '@httplug_logger.parser.transfer_stats'
```

Then reference it in your plugin config:

```
# config/packages/httplug_logger.yaml
httplug_logger:
    plugins:
        api_client:
            parser_collection: httplug_logger.parser_collection.graphql
            level_picker: httplug_logger.level_picker.default
            logger: monolog.logger.http_client
```

Customization
-------------

[](#customization)

- **Log level picker**: implement `Solitus0\HttplugLoggerBundle\LevelPicker\LogLevelPickerInterface` and point `level_picker` to your service.
- **Parsers**: implement `RequestParserInterface`, `ResponseParserInterface`, or `ExceptionParserInterface` and add to a custom `PsrHttpMessageParserCollection`.

Logged Context Shape (Default)
------------------------------

[](#logged-context-shape-default)

The log record includes a message plus structured context. Shape example (values are illustrative placeholders):

```
{
  "message": "Sending request",
  "context": {
    "httpRequest": {
      "requestMethod": "GET",
      "requestUrl": "https://example.com/resource",
      "requestSize": "123",
      "status": 200,
      "responseSize": "456",
      "latency": "0.123456s"
    },
    "jsonPayload": {
      "requestHeaders": {
        "Accept": "application/json",
        "Authorization": "REDACTED",
        "User-Agent": "YourApp/1.0"
      },
      "requestPayload": {"query": "..."},
      "responsePayload": {"data": {"id": 1}}
    },
    "transfer_stats": {
      "namelookup_time": 0.001,
      "connect_time": 0.012,
      "appconnect_time": 0.020,
      "pretransfer_time": 0.030,
      "starttransfer_time": 0.040,
      "total_time": 0.123
    },
    "client_name": "api_client"
  },
  "level": 200,
  "level_name": "INFO",
  "channel": "http_client",
  "datetime": "2025-01-01T12:00:00.000000+00:00",
  "extra": {
    "route": "/internal/endpoint",
    "remoteIp": "127.0.0.1",
    "host": "localhost",
    "userAgent": "Symfony BrowserKit"
  }
}
```

Notes:

- `extra` fields are added only when `features.request_decorator` or `features.gcp_trace_decorator` are enabled.
- `transfer_stats` and `httpRequest.latency` appear only when using the transfer-stats-aware Guzzle factory.
- Payloads are omitted or truncated based on parser settings and response headers.

Testing and QA
--------------

[](#testing-and-qa)

- `make phpstan`
- `make ecs`
- `make rector`
- `make all`

###  Health Score

28

—

LowBetter than 52% of packages

Maintenance67

Regular maintenance activity

Popularity1

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity35

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.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

192d ago

### Community

Maintainers

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

---

Top Contributors

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

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Rector

Code StyleECS

Type Coverage Yes

### Embed Badge

![Health badge](/badges/solitus0-httplug-logger-plugin/health.svg)

```
[![Health](https://phpackages.com/badges/solitus0-httplug-logger-plugin/health.svg)](https://phpackages.com/packages/solitus0-httplug-logger-plugin)
```

PHPackages © 2026

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