guzzle/log package is a niche but valuable tool for structured HTTP request/response logging in Laravel applications using Guzzle. It aligns well with:
stack, single).HttpClient (built on Guzzle) already includes middleware for logging, reducing the need for this package unless using custom Guzzle instances.HttpClient: Native middleware for logging (preferred for Laravel-specific projects).guzzlehttp/logger-middleware: Official, maintained alternative for Guzzle 6/7.guzzlehttp/logger-middleware or Laravel’s HttpClient.HttpClient middleware or guzzlehttp/logger-middleware?guzzlehttp/logger-middleware instead.guzzle/log as-is with warnings about EOL support.guzzlehttp/logger-middleware or Laravel’s HttpClient.HttpClient:
$response = Http::withOptions(['debug' => true])->get('https://api.example.com');
guzzlehttp/logger-middleware:
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Middleware;
use GuzzleHttp\Handler\CurlHandler;
$handler = HandlerStack::create(new CurlHandler());
$handler->push(Middleware::tap(function ($request) {
// Custom logging logic
}));
HttpClient middleware (native support).Monolog\Handler\StreamHandler, FirePHPHandler).// config/logging.php
'channels' => [
'guzzle' => [
'driver' => 'single',
'path' => storage_path('logs/guzzle.log'),
'level' => env('LOG_LEVEL', 'debug'),
],
],
use Guzzle3\Log\LogAdapter;
use Monolog\Logger;
$logger = new Logger('guzzle');
$logAdapter = new LogAdapter($logger);
$client = new Guzzle3\Client(['logger' => $logAdapter]);
$logger->pushProcessor(function (array $record) {
unset($record['context']['request']['headers']['authorization']);
return $record;
});
$client = new Guzzle3\Client([
'logger' => env('APP_DEBUG') ? $logAdapter : null,
]);
FilterHandler to reduce noise:
$logger->pushHandler(new \Monolog\Handler\FilterHandler(
new StreamHandler('php://stdout'),
function ($record) {
return strpos($record
How can I help you explore Laravel packages today?