Download the PHP package lightools/bitbang-http-logger without Composer
On this page you can find all versions of the php package lightools/bitbang-http-logger. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download lightools/bitbang-http-logger
More information about lightools/bitbang-http-logger
Files in lightools/bitbang-http-logger
Package bitbang-http-logger
Short Description Logger for HTTP requests and responses performed via bitbang/http library.
License MIT
Informations about the package bitbang-http-logger
Introduction
This library allows you to log all HTTP traffic performed via clients in bitbang/http library.
Installation
Basic usage
Logging
Example above will log into file (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 and you can easily change it by implementing own (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.
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 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:
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
If you are using bitbang clients in more services (for example lightools/fio and 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.