Download the PHP package gmponos/guzzle_logger without Composer
On this page you can find all versions of the php package gmponos/guzzle_logger. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
All versions of guzzle_logger with dependencies
Informations about the package guzzle_logger
Guzzle Log Middleware
This is a middleware for guzzle that will help you automatically log every request and response using a PSR-3 logger.
The middleware is functional with version 6 of Guzzle.
From now on each request and response you execute using
$client object will be logged.
By default the middleware logs every activity with level
The signature of the
LogMiddleware class is the following:
- logger - The PSR-3 logger to use for logging.
- handler - A HandlerInterface class that will be responsible for logging your request/response. Check Handlers sections.
- onFailureOnly - By default the middleware is set to log every request and response. If you wish to log the HTTP messages only when guzzle returns a rejection set this as true or when an exception occurred. Guzzle returns a rejection when http_errors option is set to true.
- logStatistics - If you set this option as true then the middleware will also log statistics about the HTTP transaction.
In order to make the middleware more flexible we allow the developer to initialize it with a handler.
A handler is the class that will be responsible for logging the HTTP message and it must implement a
As an example let's say that we create the following handler:
We can pass the handler above during construction of the middleware.
From now on all Requests will be logged. Note that at the example above only requests are logged.
If no handler is passed the middleware will initialize it's own handler. At the moment the default one is
This is the default handler used from the middleware. This handler uses internally the
FixedStrategy and logs all request
and responses with level debug. This handler adds a separate log entry for each
The information about each object are added as a
context array to the log entry.
This handler uses internally the
FixedStrategy and logs all request and responses with level debug. You can initialize this handler
with a custom strategy. This handler adds a separate log entry for each Request, Response, Exception or TransferStats.
The handler converts the objects to strings and the information about each object are added to the
message of the log entry.
Log Level Strategies
Strategies are used to define the LogLevel that the handler will use to log each object.
You can use this strategy to log each HTTP Message with a specific level.
You can use this strategy to log each HTTP Response with a specific level depending on the status code of the Response.
Using options on each request
You can set on each request options about your log.
on_exception_onlyDo not log anything unless if the response status code is above the threshold.
on_exception_onlyoption/variable is true and this is also true the middleware will log statistics about the HTTP call.
Please see CHANGELOG for more information what has changed recently.
- George Mponos
The MIT License (MIT). Please see License File for more information.