php-http/logger-plugin
PSR-3 logger plugin for HTTPlug (php-http). Logs HTTP requests/responses made through your HTTPlug client, helping you debug and monitor outgoing traffic. Install via Composer and configure with your preferred PSR-3 logger implementation.
request uri to log context in 1.5.0 improves traceability for debugging and monitoring, especially in distributed systems where HTTP requests may span multiple services. This aligns with Laravel’s observability goals (e.g., tracking API calls across microservices or third-party integrations).request uri field simplifies correlation between logs and specific API endpoints, reducing the need for manual log parsing or context-switching during troubleshooting.uri alongside method, status_code, and headers). Laravel’s Monolog can handle this extension seamlessly, especially if using structured handlers (e.g., Monolog\Handler\BufferHandler with JSON formatting).{
"level": "info",
"message": "Request completed",
"context": {
"uri": "/api/v1/users",
"method": "GET",
"status_code": 200
}
}
uri in logs may increase storage/transmission costs for high-volume systems. Mitigation:
uri in production (if not critical) via LoggerPlugin::FORMAT_TIDY or custom context filtering.FingersCrossedHandler).logstash grok patterns or filebeat processors.uri field is mapped to the correct attribute in the APM/Logs UI.uri is likely cached or extracted during request processing (not dynamically computed per log event).uri field require updates to:
Log::stack)?Monolog configuration package)?/api/v1/users/{id} with PII)? If so, will the uri be masked or excluded in production?$plugin = new LoggerPlugin($logger, true, [
'exclude' => ['uri' => '/api/v1/users/\d+']
]);
uri field enable new use cases (e.g., URI-based alerting, latency tracking)?uri inclusion/exclusion be managed across environments (dev/staging/prod)? Example:
$loggerPlugin = config('http.logger.enabled') ?
new LoggerPlugin($logger, config('http.logger.include_uri')) : null;
uri inclusion. Example in config/logging.php:
'channels' => [
'http' => [
'driver' => 'single',
'handler' => Monolog\Handler\StreamHandler::class,
'with' => [
'uri_included' => env('HTTP_LOG_URIS', true),
],
],
],
HttpPluginServiceProvider to pass the uri flag dynamically:
$this->app->singleton(\Http\Client\PluginClient::class, function ($app) {
$logger = $app->make(\Psr\Log\LoggerInterface::class);
$includeUri = config('http.logger.include_uri', true);
return new PluginClient(
new Guzzle6Adapter(new \GuzzleHttp\Client()),
[new LoggerPlugin($logger, $includeUri)]
);
});
logstash.conf to handle the new field:
filter {
grok {
match => { "message" => "%{HTTPDATE:timestamp} %{LOGLEVEL:level} %{GREEDYDATA:context}" }
remove_field => ["message"]
}
mutate {
add_field => { "uri" => "%{context:uri}" }
}
}
uri field is mapped in datadog.yaml:
logs:
- type: file
path: storage/logs/laravel.log
source: laravel
service: my-app
fields:
uri: context.uri
Phase 0: Validation (0.5 Days)
uri field works with your logging stack.composer require php-http/logger-plugin:^1.5.0
$client = new PluginClient(
new Guzzle6Adapter(new \GuzzleHttp\Client()),
[new LoggerPlugin(\Log::getMonolog(), true)]
);
$response = $client->sendRequest(new \GuzzleHttp\Psr7\Request('GET', 'https://api.example.com/data'));
uri field:
{
"context": {
"uri": "https://api.example.com/data",
...
}
}
log.context.uri: "api.example.com").Phase 1: Configuration Rollout (1 Day)
uri control via Laravel config..env:
HTTP_LOG_URIS=true
config/http.php (if using a custom config):
'logger' => [
'include_uri' => env('HTTP_LOG_URIS', true),
],
Phase 2: Tooling Updates (2–3 Days)
logstash/filebeat configs.uri field.grep, jq filters).Phase 3: Monitoring (1 Week)
uri field doesn’t introduce noise or performance issues.uri logging).Processor\UidProcessor or custom processors to enrich logs further.Monolog\Handler\SymfonyBridgeHandler).RetryPlugin, CachePlugin), as the uriHow can I help you explore Laravel packages today?