Skip to content

Commit dd64928

Browse files
committed
ICL: Callbacks for overriding request and response logging logic - readme.
1 parent 83b2611 commit dd64928

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,32 @@ $client = new Client([
339339
Now, your guzzle interactions are fully loggable. Each request, response and even errors would be logged for you.
340340
You can also set type, as a second argument. Set it to `json` to get auto json decoding for request params and response body.
341341
342+
And even more advanced options are the third and the fourth optional arguments, which are callbacks, by which you can minimize your logs if needed.
343+
Both of them should return bool. `shouldLogRequest` determines if request bodies should be logged or not, and `shouldLogResponse` determines the same for the response bodies.
344+
You can set here any of your custom logic here. For example, maybe you want to skip logging for just specific urls, or maybe you want to check content length of the response, etc.
345+
346+
```php
347+
use Psr\Http\Message\RequestInterface;
348+
use Psr\Http\Message\ResponseInterface;
349+
350+
$middleware = iclogger_guzzle_middleware($log, 'json',
351+
function (RequestInterface $request) {
352+
if (ends_with($request->getUri(), '/foo')) {
353+
return false; // skips logging for /foo request bodies
354+
}
355+
356+
return true;
357+
},
358+
function (RequestInterface $request, ResponseInterface $response) {
359+
if (ends_with($request->getUri(), '/bar')) {
360+
return false; // skips logging for /bar response bodies
361+
}
362+
363+
return true;
364+
}
365+
);
366+
```
367+
342368
#### Accessing Monolog instance
343369
344370
This package is using [Monolog logging library](https://packagist.org/packages/monolog/monolog) with all of it's power and benefits.

0 commit comments

Comments
 (0)