PHPackages                             rtheunissen/guzzle-log-middleware - 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. rtheunissen/guzzle-log-middleware

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

rtheunissen/guzzle-log-middleware
=================================

Guzzle middleware to log requests and responses

v2.0.0(2y ago)842.3M↓10.7%17[1 issues](https://github.com/rtheunissen/guzzle-log-middleware/issues)17MITPHPPHP &gt;=7.2

Since Jun 12Pushed 2y ago1 watchersCompare

[ Source](https://github.com/rtheunissen/guzzle-log-middleware)[ Packagist](https://packagist.org/packages/rtheunissen/guzzle-log-middleware)[ RSS](/packages/rtheunissen-guzzle-log-middleware/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (4)Versions (15)Used By (17)

Guzzle 6/7 middleware to log requests and responses
===================================================

[](#guzzle-67-middleware-to-log-requests-and-responses)

[![Author](https://camo.githubusercontent.com/989b5323df87a6d4fe899296ec948ba333af9e04bbe23add7962dd26def71220/687474703a2f2f696d672e736869656c64732e696f2f62616467652f617574686f722d40727564695f746865756e697373656e2d626c75652e7376673f7374796c653d666c61742d737175617265)](https://twitter.com/rudi_theunissen)[![License](https://camo.githubusercontent.com/51c374fbd284b35c8af582e93f019a327c80ac5a0e5eb02b5f826061ed56a952/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f72746865756e697373656e2f67757a7a6c652d6c6f672d6d6964646c65776172652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/rtheunissen/guzzle-log-middleware)[![Latest Version](https://camo.githubusercontent.com/766a2597631147168a359974637c1dfbae55eb024a3b196bf508cebfdd34441b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f72746865756e697373656e2f67757a7a6c652d6c6f672d6d6964646c65776172652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/rtheunissen/guzzle-log-middleware)[![Build Status](https://camo.githubusercontent.com/e2a1e5b1f67bbaa0bb0d8522a222985ff445f041a578d55da887201553eac4bc/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f72746865756e697373656e2f67757a7a6c652d6c6f672d6d6964646c65776172652e7376673f7374796c653d666c61742d737175617265266272616e63683d6d6173746572)](https://travis-ci.org/rtheunissen/guzzle-log-middleware)[![Scrutinizer](https://camo.githubusercontent.com/d1b12c1184190cca831118e1872e051f5459ac83783573013630f355b62671e7/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f72746865756e697373656e2f67757a7a6c652d6c6f672d6d6964646c65776172652e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/rtheunissen/guzzle-log-middleware/)[![Scrutinizer Coverage](https://camo.githubusercontent.com/7edf58d9534f26f5f18aa173c610d8ade99b712a5a108373e2d065dc5892fc83/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f72746865756e697373656e2f67757a7a6c652d6c6f672d6d6964646c65776172652e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/rtheunissen/guzzle-log-middleware/)

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

[](#installation)

```
composer require rtheunissen/guzzle-log-middleware
```

Usage
-----

[](#usage)

```
use Concat\Http\Middleware\Logger;

```

### Logger

[](#logger)

You can use either a [PSR-3](http://www.php-fig.org/psr/psr-3/) logger (such as [Monolog](https://github.com/Seldaek/monolog)) or a callable that accepts a log level, message, and context as an array.

```
$middleware = new Logger($logger);
```

or

```
$middleware = new Logger(function ($level, $message, array $context) {
    // Log the message
});
```

#### Log level

[](#log-level)

You can set a log level as a string or a callable that accepts a response. If the response is not set, it can be assumed that it's a request-only log, or that the request has been rejected. If the log level is not set, the default log level will be used which is `LogLevel::NOTICE` for status codes &gt;= 400, or `LogLevel::INFO` otherwise.

```
use Psr\Log\LogLevel;

$middleware->setLogLevel(LogLevel::DEBUG);
```

or

```
$middleware->setLogLevel(function ($response) {
    // Return log level
});
```

#### Formatter

[](#formatter)

You can set a message formatter as a [MessageFormatter](https://github.com/guzzle/guzzle/blob/master/src/MessageFormatter.php) or a callable that accepts a request, response, as well as a reason when a request has been rejected.

```
$middleware->setFormatter($formatter);
```

or

```
$middleware->setFormatter(function ($request, $response, $reason) {
    // Return log message
});
```

or

```
$middleware = new Logger($logger, $formatter);
```

#### Request logging

[](#request-logging)

A request will only be logged when its response is received. You can enable request logging by using `$middleware->setRequestLoggingEnabled(true)`, which will log a request when it is requested, as well as its response when it is received. Any `$response` references will be `null` in the case where only the request exists.

#### Middleware

[](#middleware)

This package is designed to function as [Guzzle 6/7 Middleware](http://guzzle.readthedocs.org/en/latest/handlers-and-middleware.html#middleware).

###  Health Score

46

—

FairBetter than 93% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity55

Moderate usage in the ecosystem

Community28

Small or concentrated contributor base

Maturity66

Established project with proven stability

 Bus Factor1

Top contributor holds 86.4% 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 ~227 days

Recently: every ~406 days

Total

14

Last Release

1034d ago

Major Versions

v0.4.2 → v1.0.02020-11-02

v1.1.0 → v2.0.02023-07-19

PHP version history (2 changes)v0.0.1PHP &gt;=5.5

v1.0.0PHP &gt;=7.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/761df764fa80c32031884a5dd2376cf7e70c0fa152eaa141fd68f12b4a761b9f?d=identicon)[rtheunissen](/maintainers/rtheunissen)

---

Top Contributors

[![rtheunissen](https://avatars.githubusercontent.com/u/809191?v=4)](https://github.com/rtheunissen "rtheunissen (38 commits)")[![kielabokkie](https://avatars.githubusercontent.com/u/1221750?v=4)](https://github.com/kielabokkie "kielabokkie (2 commits)")[![dbclkh](https://avatars.githubusercontent.com/u/21057488?v=4)](https://github.com/dbclkh "dbclkh (1 commits)")[![hopeseekr](https://avatars.githubusercontent.com/u/1125541?v=4)](https://github.com/hopeseekr "hopeseekr (1 commits)")[![module17](https://avatars.githubusercontent.com/u/157851?v=4)](https://github.com/module17 "module17 (1 commits)")[![ricardo-wtl](https://avatars.githubusercontent.com/u/128471479?v=4)](https://github.com/ricardo-wtl "ricardo-wtl (1 commits)")

---

Tags

httplogmiddlewareGuzzlepsr7

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/rtheunissen-guzzle-log-middleware/health.svg)

```
[![Health](https://phpackages.com/badges/rtheunissen-guzzle-log-middleware/health.svg)](https://phpackages.com/packages/rtheunissen-guzzle-log-middleware)
```

###  Alternatives

[kevinrob/guzzle-cache-middleware

A HTTP/1.1 Cache for Guzzle 6. It's a simple Middleware to be added in the HandlerStack. (RFC 7234)

43117.4M104](/packages/kevinrob-guzzle-cache-middleware)[rtheunissen/guzzle-rate-limiter

Guzzle 6 middleware used to delay requests dynamically

52177.2k1](/packages/rtheunissen-guzzle-rate-limiter)[eljam/guzzle-jwt-middleware

A jwt authentication middleware for guzzle 6

28722.5k3](/packages/eljam-guzzle-jwt-middleware)[hannesvdvreken/guzzle-debugbar

A Guzzle middleware that logs requests to debugbar's timeline

76410.4k1](/packages/hannesvdvreken-guzzle-debugbar)[gmponos/guzzle_logger

A Guzzle middleware to log request and responses automatically

772.2M6](/packages/gmponos-guzzle-logger)[rtheunissen/guzzle-cache-handler

Guzzle 6/7 handler used to cache responses

12142.8k](/packages/rtheunissen-guzzle-cache-handler)

PHPackages © 2026

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