Skip to content
This repository was archived by the owner on Sep 6, 2019. It is now read-only.

Commit 3c5aa41

Browse files
committed
updated readme and configs
1 parent a9f53a5 commit 3c5aa41

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

README.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ Next run `php artisan config:publish pulkitjalan/requester` to publish the confi
4646

4747
The requester class has a dependency of `guzzle` and takes in an instance of `guzzle` as the first param.
4848

49+
This package also uses a few guzzle subscribers. `https://github.com/guzzle/retry-subscriber` for retry functionality and `https://github.com/guzzle/log-subscriber` for logging.
50+
4951
Available request methods: `get`, `head`, `delete`, `put`, `patch`, `post`, `options`
5052

5153
```php
@@ -60,7 +62,7 @@ $requester = new Requester(new GuzzleClient());
6062
$requester->url('example.com')->get();
6163
```
6264

63-
Altering the default retry behaviour
65+
Altering the default retry behaviour. See [retry-subscriber](https://github.com/guzzle/retry-subscriber) for more info.
6466
```php
6567
// retry 10 times, with a 1 second wait on a 503 error
6668
$requester->url('example.com')->retry(10)->every(1000)->on([503])->get();
@@ -117,3 +119,21 @@ $this->response = $response->then(function ($response) {
117119
// Use the response synchronously
118120
$this->response = $response->getBody();
119121
```
122+
123+
Logging guzzle requests to file. See [log-subscriber](https://github.com/guzzle/log-subscriber) for more info.
124+
```php
125+
use PulkitJalan\Requester\Requester;
126+
use GuzzleHttp\Client as GuzzleClient;
127+
use Monolog\Logger;
128+
use Monolog\Handler\StreamHandler;
129+
130+
// create a log channel
131+
$log = new Logger('name');
132+
$log->pushHandler(new StreamHandler('/path/to/your.log', Logger::INFO));
133+
134+
$requester = new Requester(new GuzzleClient());
135+
$requester->addLogger($log);
136+
137+
// request and response logged to file
138+
$requester->url('example.com')->get();
139+
```

src/Requester.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public function getGuzzleClient()
112112
* @param string $format Log output format
113113
* @return void
114114
*/
115-
public function addLogger($logger, $format)
115+
public function addLogger($logger, $format = 'CLF')
116116
{
117117
if (defined(Formatter::class.'::'.$format)) {
118118
$format = constant(Formatter::class.'::'.$format);

src/config/config.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@
108108
|--------------------------------------------------------------------------
109109
|
110110
| The Log Subscriber currently supports [CLF, DEBUG, SHORT]
111-
| See https://github.com/guzzle/log-subscriber/blob/master/src/Formatter.php
111+
| See https://github.com/guzzle/log-subscriber for more info
112112
| Can also set a custom format
113113
|
114114
*/

0 commit comments

Comments
 (0)