bit-mx/saloon-logger-plug-in
Laravel plug-in for Saloon v3 that logs HTTP requests, responses, and exceptions to the database with a shared ULID trace_id for end-to-end traceability. Includes automatic sanitization of sensitive headers/fields and simple trait-based setup.
saloon-logger-plugin extends Laravel’s Saloon (a PHP HTTP client library) by adding structured logging capabilities. This aligns well with Laravel applications requiring debuggable, audit-friendly HTTP interactions (e.g., APIs, webhooks, or third-party services).| Risk Area | Mitigation Strategy |
|---|---|
| Saloon Version Lock | Test against Saloon’s latest stable branch if not using v4+. |
| Log Overhead | Configure log levels (e.g., debug only for dev) to avoid performance impact. |
| Payload Sensitivity | Sanitize logs for PII (e.g., tokens, passwords) via Saloon’s mask() or middleware. |
| Breaking Changes | Monitor Saloon’s roadmap; plugin may need updates if Saloon’s core logging changes. |
Saloon\Http\Client).Middleware or LogMiddleware may suffice.tap() or throwIf().single, daily, syslog, or custom channels.file_get_contents).GuzzleHttp\Client with Saloon\Http\Client.use Saloon\Http\Client;
use BitMx\SaloonLoggerPlugin\LoggerPlugin;
$client = new Client(base_url: 'https://api.example.com');
$client->withPlugin(new LoggerPlugin()); // Enable logging
config/logging.php:
'channels' => [
'saloon' => [
'driver' => 'single',
'path' => storage_path('logs/saloon.log'),
'level' => env('SALOON_LOG_LEVEL', 'debug'),
'format' => Monolog\Formatter\JsonFormatter::class,
],
],
Saloon\Plugins\RetryPlugin).json_encode for payloads).LoggerPlugin and validate log output format.saloon-logger-plugin for breaking changes (MIT license allows forks if needed).log-rotate or custom cron jobs).composer.json to avoid unexpected updates."require": {
"saloon-php/saloon": "^4.0",
"bit-mx/saloon-logger-plugin": "^1.0"
}
{
"timestamp": "2025-11-11T12:00:00+00:00",
"level": "debug",
"context": {
"client": "PaymentGatewayClient",
"method": "POST",
"url": "https://api.example.com/charge",
"headers": {"Authorization": "Bearer ***"},
"payload": {"amount": 100, "currency": "USD"},
"response": {"status": 200, "body": {"id": "ch_123"}},
"duration_ms": 150
}
}
log_level: 'info' in production for critical paths.| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Logger Plugin Fails | No logs for HTTP clients. | Fallback to Saloon’s default logging. |
| Log File Permissions | Logs not written. | Ensure storage/logs is writable. |
| Payload Too Large | Logs exceed disk quotas. | Configure max_log_size in Monolog. |
| Sensitive Data Leaked | PII in logs. | Use Saloon’s mask() for sensitive fields. |
| High Cardinality Logs | Overwhelms log aggregation. | Filter logs by client or method. |
How can I help you explore Laravel packages today?