You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Enabled only on individual HTTP Client instances, using `Http::log()` - no global logging.
54
54
- Log channel name can be set per HTTP Client instance by passing a name to `Http::log($name)`
55
+
-**Variant 3: Global HTTP Middleware**
56
+
- Can be used in combination with other `Http::globalRequestMiddleware()` calls in your `AppServiceProvider`'s `boot()` method, after registering your [Global Middleware](https://laravel.com/docs/10.x/http-client#global-middleware).
57
+
55
58
56
59
## Usage
57
60
61
+
> **NOTE:** For all 3 variants below, you need to keep the HTTP Client Global Logger enabled (not setting `HTTP_CLIENT_GLOBAL_LOGGER_ENABLED=false` in your `.env`). The `http-client-global-logger.enabled` config option is a global on/off switch for all 3 variants, not just the "global" variants. Our project name might be misleading in that context.
62
+
58
63
### Variant 1: Global Logging
59
64
60
65
**Just use Laravel HTTP Client as always - no need to configure anything!**
If you use [Global Middleware](https://laravel.com/docs/10.x/http-client#global-middleware) (`Http::globalRequestMiddleware()` and `Http::globalResponseMiddleware()` methods), you should be aware that *Variant 1* uses Laravel's `RequestSending` event to log HTTP requests. This event is fired **before** Global Middleware is executed. Therefore, any modifications to the request made by Global Middleware will not be logged. To overcome this, this package provides a middleware that you may add after your Global Middleware.
114
+
115
+
You may add the middleware using the static `addRequestMiddleware()` method on the `HttpClientLogger` class:
116
+
117
+
```php
118
+
use Onlime\LaravelHttpClientGlobalLogger\HttpClientLogger;
119
+
120
+
HttpClientLogger::addRequestMiddleware();
121
+
```
122
+
123
+
For example, you may add this to your `AppServiceProvider`'s `boot()` method after registering your Global Middleware:
124
+
125
+
```php
126
+
use Illuminate\Support\Facades\Http;
127
+
use Onlime\LaravelHttpClientGlobalLogger\HttpClientLogger;
By default, logs are written to a separate logfile `http-client.log`.
@@ -146,9 +176,9 @@ So, my recommendation: If you need global logging without any extra configuratio
146
176
## Caveats
147
177
148
178
- This package currently uses two different implementations for logging. In the preferred variant 1 (global logging), it is currently not possible to configure the [log channel name](https://laravel.com/docs/logging#configuring-the-channel-name) which defaults to current environment, such as `production` or `local`. If you with to use Laravel HTTP Client to access multiple different external APIs, it is nice to explicitely distinguish between them by different log channel names.
149
-
179
+
150
180
As a workaround, I have implemented another way of logging through `Http::log()` method as mixin. But of course, we should combine both variants into a single one for a cleaner codebase.
151
-
181
+
152
182
- Very basic obfuscation support using regex with lookbehind assertions (e.g. `/(?<=Authorization:\sBearer ).*/m`, modifying formatted log output. It's currently not possible to directly modify request headers or JSON data in request body.
153
183
154
184
- Obfuscation currently only works in variant 1 (global logging).
0 commit comments