PHPackages                             lightools/bitbang-http-logger - 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. lightools/bitbang-http-logger

ActiveLibrary[Logging &amp; Monitoring](/categories/logging)

lightools/bitbang-http-logger
=============================

Logger for HTTP requests and responses performed via bitbang/http library.

1.1.0(3y ago)17.2k↓100%MITPHPPHP &gt;=5.4

Since Mar 29Pushed 1y ago1 watchersCompare

[ Source](https://github.com/lightools/bitbang-http-logger)[ Packagist](https://packagist.org/packages/lightools/bitbang-http-logger)[ RSS](/packages/lightools-bitbang-http-logger/feed)WikiDiscussions master Synced 1mo ago

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

Introduction
------------

[](#introduction)

This library allows you to log all HTTP traffic performed via clients in [bitbang/http](https://github.com/bitbang/http) library.

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

[](#installation)

```
$ composer require lightools/bitbang-http-logger
```

Basic usage
-----------

[](#basic-usage)

```
$writer = new Lightools\BitbangLogger\Writers\DefaultWriter(__DIR__ . '/logs/http');
$logger = new Lightools\BitbangLogger\HttpLogger($writer);

$client = new Bitbang\Http\Clients\CurlClient();
$client->onRequest([$logger, 'onRequest']);
$client->onResponse([$logger, 'onResponse']);

$url = 'https://maps.googleapis.com/maps/api/distancematrix/json?origins=Praha&destinations=Brno';
$request = new Bitbang\Http\Request(Bitbang\Http\Request::GET, $url);

try {
    $client->process($request);
} catch (Bitbang\Http\BadResponseException $e) {
    // process exception
}
```

### Logging

[](#logging)

Example above will log into file `./logs/http/2016-03-22/17-25-00-44956900_56fa569cc8c8d.txt` (contents shown below). You can see that request and response are in the same file and some timestamps are included above both HTTP messages. This behavior is done by `DefaultWriter` and you can easily change it by implementing own `IWritter`(you may want to save HTTP request and response separately, change the file naming or store logs in database). DefaultWriter also saves whole HTTP communication when some redirect occurs - all subsequent HTTP requests will be stored in one file.

```
(17-25-00-44956900)
GET https://maps.googleapis.com/maps/api/distancematrix/json?origins=Praha&destinations=Brno HTTP/1.1
expect:
connection: keep-alive
user-agent: Bitbang/0.3.0 (cURL)

(17-25-00-77731500)
HTTP/1.1 200
content-type: application/json; charset=UTF-8
date: Tue, 22 Mar 2016 16:25:27 GMT
expires: Wed, 23 Mar 2016 16:25:27 GMT
cache-control: public, max-age=86400
content-encoding: gzip
server: mafe
x-xss-protection: 1; mode=block
x-frame-options: SAMEORIGIN
alternate-protocol: 443:quic,p=1
alt-svc: quic=":443"; ma=2592000; v="31,30,29,28,27,26,25"
transfer-encoding: chunked

{
   "destination_addresses" : [ "Brno, Česká republika" ],
   "origin_addresses" : [ "Praha, Česká republika" ],
   "rows" : [
      {
         "elements" : [
            {
               "distance" : {
                  "text" : "205 km",
                  "value" : 205461
               },
               "duration" : {
                  "text" : "2 hod, 0 min",
                  "value" : 7217
               },
               "status" : "OK"
            }
         ]
      }
   ],
   "status" : "OK"
}

```

Formatting
----------

[](#formatting)

By default, HTTP body is printed to log as it was set to Request or Response object, but you can register formatters to make it prettier and more readable. All you need is to implement `IFormatter` interface and register it in logger. This library is shipped with few handy formatters - for array (typical POST), JSON, XML or for urlencoded HTTP body. ArrayFormatter also supports quite common CURLFile.

The first formatter that is able to format HTTP message is used, so theoretically it may matter in which order you register them. Here is example how to use all default formatters:

```
$xmlLoader = new Lightools\Xml\XmlLoader();
$arrayDumper = new Lightools\BitbangLogger\ArrayDumper();

$arrayFormatter = new Lightools\BitbangLogger\Formatters\ArrayFormatter($arrayDumper);
$urlFormatter = new Lightools\BitbangLogger\Formatters\UrlEncodedFormatter($arrayDumper);
$jsonFormatter = new Lightools\BitbangLogger\Formatters\JsonFormatter(); // requires nette/utils to work
$xmlFormatter = new Lightools\BitbangLogger\Formatters\XmlFormatter($xmlLoader); // requires lightools/xml to work

$writer = new Lightools\BitbangLogger\Writers\DefaultWriter(__DIR__ . '/logs/http');
$logger = new Lightools\BitbangLogger\HttpLogger($writer);
$logger->registerFormatter($arrayFormatter);
$logger->registerFormatter($urlFormatter);
$logger->registerFormatter($jsonFormatter);
$logger->registerFormatter($xmlFormatter);
```

Limitations
-----------

[](#limitations)

Logged HTTP headers may not contain all really sent headers because some of them might be modified by proxies or even by curl library itself (e.g. very handy CURLOPT\_ENCODING).

Multiple HTTP clients
---------------------

[](#multiple-http-clients)

If you are using bitbang clients in more services (for example [lightools/fio](https://github.com/lightools/fio) and [lightools/ares](https://github.com/lightools/ares)), and you don't want to store all logs in the same folder, custom IWriter or some HttpLoggerFactory and HttpClientFactory might be handy.

How to run tests
----------------

[](#how-to-run-tests)

```
$ vendor/bin/tester tests
```

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance31

Infrequent updates — may be unmaintained

Popularity23

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity60

Established project with proven stability

 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 ~2424 days

Total

2

Last Release

1268d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/5b545e3f9d982d538f11bc42b3dc2d186f706cef92c8bc8bc8f8788b08186ea5?d=identicon)[janedbal](/maintainers/janedbal)

---

Top Contributors

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

---

Tags

bitbanghttplogger

### Embed Badge

![Health badge](/badges/lightools-bitbang-http-logger/health.svg)

```
[![Health](https://phpackages.com/badges/lightools-bitbang-http-logger/health.svg)](https://phpackages.com/packages/lightools-bitbang-http-logger)
```

###  Alternatives

[psr/log

Common interface for logging libraries

10.4k1.2B9.1k](/packages/psr-log)[itsgoingd/clockwork

php dev tools in your browser

5.9k27.6M93](/packages/itsgoingd-clockwork)[graylog2/gelf-php

A php implementation to send log-messages to a GELF compatible backend like Graylog2.

41838.2M137](/packages/graylog2-gelf-php)[bugsnag/bugsnag-psr-logger

Official Bugsnag PHP PSR Logger.

32132.5M2](/packages/bugsnag-bugsnag-psr-logger)[consolidation/log

Improved Psr-3 / Psr\\Log logger based on Symfony Console components.

15462.2M7](/packages/consolidation-log)[datadog/php-datadogstatsd

An extremely simple PHP datadogstatsd client

19124.6M15](/packages/datadog-php-datadogstatsd)

PHPackages © 2026

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