PHPackages                             tiny-blocks/http-logging - 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. tiny-blocks/http-logging

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

tiny-blocks/http-logging
========================

PSR-15 middleware that logs HTTP request and response metadata with request duration.

1.0.0(today)10MITPHPPHP ^8.5CI passing

Since Jul 1Pushed todayCompare

[ Source](https://github.com/tiny-blocks/http-logging)[ Packagist](https://packagist.org/packages/tiny-blocks/http-logging)[ Docs](https://github.com/tiny-blocks/http-logging)[ RSS](/packages/tiny-blocks-http-logging/feed)WikiDiscussions main Synced today

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

Http Logging
============

[](#http-logging)

[![License](https://camo.githubusercontent.com/f8df3091bbe1149f398a5369b2c39e896766f9f6efba3477c63e9b4aa940ef14/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d677265656e)](https://github.com/tiny-blocks/http-logging/blob/main/LICENSE)

- [Overview](#overview)
- [Installation](#installation)
- [How to use](#how-to-use)
    - [Wiring the middleware](#wiring-the-middleware)
    - [Correlated logs](#correlated-logs)
    - [Customizing the clock](#customizing-the-clock)
- [License](#license)
- [Contributing](#contributing)

Overview
--------

[](#overview)

Provides a PSR-15 middleware that records every inbound HTTP exchange. Before invoking the next handler, the middleware logs the request method, URI, query parameters, and parsed body. After the handler runs, it logs the response status code, decoded JSON body when present, and the elapsed duration in milliseconds. Successful responses are logged at `info` level. Responses in the 4xx/5xx range are logged at `error` level.

Duration is measured through a `TinyBlocks\Time\MonotonicClock` and a `Stopwatch`, so the reading is unaffected by wall-clock adjustments. When the request carries a correlation identifier (under the `correlationId`attribute, as exposed by [tiny-blocks/http-correlation-id](https://github.com/tiny-blocks/http-correlation-id)), every log entry produced by this middleware is automatically tagged with the `correlation_id` context key through the `CorrelatedLogger` collaborator.

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

[](#installation)

```
composer require tiny-blocks/http-logging
```

How to use
----------

[](#how-to-use)

### Wiring the middleware

[](#wiring-the-middleware)

Builds the middleware with a PSR-3 logger and processes a request through it.

```
