PHPackages                             hrodic/guzzle5-log-subscriber - 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. hrodic/guzzle5-log-subscriber

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

hrodic/guzzle5-log-subscriber
=============================

Logs HTTP requests and responses as they are sent over the wire (Guzzle 4+)

1.0.2(10y ago)03.9kMITPHPPHP &gt;=5.4.0

Since Mar 16Pushed 10y ago1 watchersCompare

[ Source](https://github.com/hrodic/guzzle5-log-subscriber)[ Packagist](https://packagist.org/packages/hrodic/guzzle5-log-subscriber)[ Docs](http://guzzlephp.org/)[ RSS](/packages/hrodic-guzzle5-log-subscriber/feed)WikiDiscussions master Synced 2mo ago

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

Whats new?
----------

[](#whats-new)

It works with Streams (bugfixed)

Guzzle Log Subscriber
---------------------

[](#guzzle-log-subscriber)

The LogSubscriber logs HTTP requests and responses to a [PSR-3 logger](https://github.com/php-fig/log), callable, resource returned by `fopen()`, or by calling `echo()`.

Here's the simplest example of how it's used:

```
use GuzzleHttp\Client;
use GuzzleHttp\Subscriber\Log\LogSubscriber;

$client = new Client();
$client->getEmitter()->attach(new LogSubscriber());
$client->get('http://httpbin.org');
```

Running the above example will echo a message using the [Apache Common Log Format (CLF)](http://httpd.apache.org/docs/1.3/logs.html#common).

```
[info] hostname Guzzle/5.0 curl/7.21.4 PHP/5.5.7 - [2014-03-01T22:48:13+00:00] "GET / HTTP/1.1" 200 7641
```

Note

Because no logger is provided, the subscriber simply logs messages with `echo()`. This is the method used for logging if `null` is provided.

### Installing

[](#installing)

This project can be installed using Composer. Add the following to your composer.json:

```
{
    "require": {
        "guzzlehttp/log-subscriber": "~1.0"
    }
}
```

### Using PSR-3 Loggers

[](#using-psr-3-loggers)

You can provide a PSR-3 logger to the constructor as well. The following example shows how the LogSubscriber can be combined with [Monolog](https://github.com/Seldaek/monolog).

```
use GuzzleHttp\Client;
use GuzzleHttp\Subscriber\Log\LogSubscriber;
use Monolog\Logger;
use Monolog\Handler\StreamHandler;

// create a log channel
$log = new Logger('name');
$log->pushHandler(new StreamHandler('/path/to/your.log', Logger::WARNING));

$client = new Client();
$subscriber = new LogSubscriber($log);
$client->getEmitter()->attach($subscriber);
```

### Logging with a custom message format

[](#logging-with-a-custom-message-format)

The LogSubscriber's constructor accepts a logger as the first argument and a message format string or a message formatter as the second argument. You could log the full HTTP request and Response message using the debug format via `GuzzleHttp\Subscriber\Log\Formatter::DEBUG`.

```
use GuzzleHttp\Subscriber\Log\LogSubscriber;
use GuzzleHttp\Subscriber\Log\Formatter;

// Log the full request and response messages using echo() calls.
$subscriber = new LogSubscriber(null, Formatter::DEBUG);
```

#### Message Formatter

[](#message-formatter)

Included in this repository is a *message formatter*. The message formatter is used to format log messages for both requests and responses using a log template that uses variable substitution for string enclosed in braces (`{}`).

The following variables are available in message formatter templates:

{request}Full HTTP request message{response}Full HTTP response message{ts}Timestamp{host}Host of the request{method}Method of the request{url}URL of the request{protocol}Request protocol{version}Protocol version{resource}Resource of the request (path + query + fragment){hostname}Hostname of the machine that sent the request{code}Status code of the response (if available){phrase}Reason phrase of the response (if available){error}Any error messages (if available){req\_header\_\*}Replace `*` with the lowercased name of a request header to add to the message.{res\_header\_\*}Replace `*` with the lowercased name of a response header to add to the message{req\_headers}Request headers as a string.{res\_headers}Response headers as a string.{req\_body}Request body as a string.{res\_body}Response body as a string.

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 68.8% 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 ~244 days

Total

4

Last Release

3708d ago

Major Versions

0.1.0 → 1.0.02014-03-30

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1694951?v=4)[Rodrigo](/maintainers/hrodic)[@hrodic](https://github.com/hrodic)

---

Top Contributors

[![mtdowling](https://avatars.githubusercontent.com/u/190930?v=4)](https://github.com/mtdowling "mtdowling (22 commits)")[![GrahamCampbell](https://avatars.githubusercontent.com/u/2829600?v=4)](https://github.com/GrahamCampbell "GrahamCampbell (5 commits)")[![hrodic](https://avatars.githubusercontent.com/u/1694951?v=4)](https://github.com/hrodic "hrodic (5 commits)")

---

Tags

logpluginGuzzle

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/hrodic-guzzle5-log-subscriber/health.svg)

```
[![Health](https://phpackages.com/badges/hrodic-guzzle5-log-subscriber/health.svg)](https://phpackages.com/packages/hrodic-guzzle5-log-subscriber)
```

###  Alternatives

[rtheunissen/guzzle-log-middleware

Guzzle middleware to log requests and responses

842.3M17](/packages/rtheunissen-guzzle-log-middleware)[gmponos/guzzle_logger

A Guzzle middleware to log request and responses automatically

772.2M6](/packages/gmponos-guzzle-logger)[bilfeldt/laravel-http-client-logger

A logger for the Laravel HTTP Client

1531.6M3](/packages/bilfeldt-laravel-http-client-logger)[hannesvdvreken/guzzle-debugbar

A Guzzle middleware that logs requests to debugbar's timeline

76410.4k1](/packages/hannesvdvreken-guzzle-debugbar)

PHPackages © 2026

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