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

Abandoned → [see rtheunissen/guzzle-log-middleware](/?search=see%20rtheunissen%2Fguzzle-log-middleware)Library[HTTP &amp; Networking](/categories/http)

vbukreyev/guzzle-log-middleware
===============================

Guzzle middleware to log requests and responses

v0.4.0(10y ago)038MITPHPPHP &gt;=5.5

Since Jun 12Pushed 9y ago1 watchersCompare

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

READMEChangelogDependencies (4)Versions (9)Used By (0)

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

[](#guzzle-6-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 vbukreyev/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.

```
$logger = new myLogger(); // should implements Psr\Log\LoggerInterface
$middleware = new Logger($logger);
$middleware->setLogLevel(LogLevel::DEBUG);
$middleware->setFormatter(new \GuzzleHttp\MessageFormatter(myLogger::MY_FORMAT));
$middleware->setRequestLoggingEnabled(false);

$stack = \GuzzleHttp\HandlerStack::create();
$stack->push($middleware->logHandler());

$client = new GuzzleHttp\Client([

  'handler' => $stack,

]);

###

class myLogger  extends \Psr\Log\AbstractLogger {

  const MY_FORMAT = "{hostname} {req_header_User-Agent} - [{date_common_log}] \"{method} {target} HTTP/{version}\" {code} {res_header_Content-Length} :: {req_body}";

  public function log($level, $message, array $context = array()) {

    file_put_contents('/tmp/my-logger.log', $message . PHP_EOL, FILE_APPEND);

  }

}
```

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 Middleware](http://guzzle.readthedocs.org/en/latest/handlers-and-middleware.html#middleware).

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 96.7% 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

8

Last Release

3990d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/6c57d0a4d454d66e5b9f48889005349527ed9c84202d22e799082d728493d47f?d=identicon)[vbukreyev](/maintainers/vbukreyev)

---

Top Contributors

[![rtheunissen](https://avatars.githubusercontent.com/u/809191?v=4)](https://github.com/rtheunissen "rtheunissen (29 commits)")[![module17](https://avatars.githubusercontent.com/u/157851?v=4)](https://github.com/module17 "module17 (1 commits)")

---

Tags

httplogmiddlewareGuzzlepsr7

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[rtheunissen/guzzle-log-middleware

Guzzle middleware to log requests and responses

842.3M17](/packages/rtheunissen-guzzle-log-middleware)[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)

43417.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)

PHPackages © 2026

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