Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Guzzle Log Middleware

Guzzle Log Middleware Laravel Package

rtheunissen/guzzle-log-middleware

Lightweight Guzzle middleware for logging HTTP requests and responses. Capture method, URL, headers, body, status and timing, and route logs through PSR-3/Monolog with configurable formats, levels, and filtering—ideal for debugging and auditing API traffic.

View on GitHub
Deep Wiki
Context7

Guzzle 6 middleware used to log requests and responses

Frequently asked questions about Guzzle Log Middleware
How do I install and use this middleware in a Laravel app?
Run `composer require rtheunissen/guzzle-log-middleware`, then inject the `Logger` class into your Guzzle client or Laravel’s HTTP facade. For example, use `Http::withMiddleware(new Logger($logger))` where `$logger` is a PSR-3 logger like Monolog. The package works seamlessly with Laravel’s HTTP client.
Does this package work with Laravel’s HTTP client facade (Http::)?
Yes, it fully supports Laravel’s HTTP facade. Use `Http::withMiddleware(new Logger($logger))` to wrap requests with logging. This is the recommended approach for most Laravel applications to avoid modifying core Guzzle clients.
Can I customize the log format (e.g., JSON) for better observability?
Absolutely. Use the `setFormatter()` method to pass a custom formatter or a callable that returns formatted strings. For JSON logs, leverage Guzzle’s `MessageFormatter` or create a custom one. This is especially useful for tools like ELK or Datadog.
What Laravel and Guzzle versions does this package support?
The package targets Guzzle 6.x (compatible with Laravel 7+), but may require minor adjustments for Guzzle 7+. Laravel 8/9 users should verify compatibility with their Guzzle version. Check the [README](https://github.com/rtheunissen/guzzle-log-middleware) for updates.
How do I filter logs to avoid excessive volume (e.g., skip 200 responses)?
Use the `setLogLevel()` method with a callable to dynamically set log levels. For example, log only errors by returning `LogLevel::ERROR` for responses with status codes >= 400. This reduces noise while keeping critical logs intact.
Will this middleware impact performance in production?
Logging adds minimal overhead, but high-traffic apps may need optimizations. Use async logging (e.g., Monolog’s async handlers) or sample logs (e.g., log only failed requests). Avoid logging sensitive payloads like passwords to maintain performance and security.
Can I integrate this with Laravel’s default logging (e.g., `Log::channel()`)?
Yes, pass Laravel’s Log facade (or a Monolog instance) to the `Logger` constructor. For example, `new Logger(Log::channel('single'))` will route logs to Laravel’s default storage/logs/laravel.log or a custom channel.
How do I log requests/responses to an external system like Datadog or Sentry?
Configure a Monolog handler (e.g., `DatadogHandler` or `SentryHandler`) and pass it to the `Logger`. The middleware outputs structured data, making it easy to forward logs to external tools. Ensure your formatter aligns with the target system’s requirements.
What if I need to log only specific endpoints or exclude certain requests?
Use the `setFormatter()` callable to conditionally log requests. For example, skip logging for `/health` endpoints or redact sensitive data from payloads. This gives you fine-grained control over log granularity.
Are there alternatives to this package for logging Guzzle requests in Laravel?
Alternatives include custom Guzzle middleware with Monolog or Laravel’s `Log` facade, or packages like `spatie/laravel-guzzle-logging`. However, this package offers a dedicated, lightweight solution with built-in PSR-3 support and flexible formatting, making it ideal for Laravel’s ecosystem.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky
spatie/mailcoach-vapor