spatie/flare-debug-sender
Debug sender for Flare payloads, mainly for internal testing. Plug it into Laravel’s Flare config to inspect, log, or forward payloads, optionally printing full payload details and controlling passthrough/trace handling via configurable channels and sender options.
Installation:
composer require spatie/flare-debug-sender
Publish the config file (if needed):
php artisan vendor:publish --provider="Spatie\FlareDebugSender\FlareDebugSenderServiceProvider" --tag="config"
First Use Case:
config/flare.php:
'senders' => [
// ...
\Spatie\FlareDebugSender\FlareDebugSender::class,
],
php artisan flare:debug or Flare::debug() in code).storage/logs/flare-debug.log).Where to Look First:
config/flare.php (ensure the sender is enabled).storage/logs/flare-debug.log (default output location).Spatie\FlareDebugSender\FlareDebugSenderServiceProvider (for bootstrapping).Debugging Flare Payloads Locally:
Flare::debug() in your code to capture payloads without sending them to the Flare server.use FlareClient\Flare;
Flare::debug('User login failed', ['user_id' => 123]);
storage/logs/flare-debug.log in JSON format.Integration with Laravel Exceptions:
use Illuminate\Foundation\Exceptions\Handler;
use Spatie\FlareDebugSender\FlareDebugSender;
public function report(Throwable $exception)
{
FlareDebugSender::send($exception);
parent::report($exception);
}
Conditional Debugging:
// In config/flare.php
'flare_debug_sender' => env('FLARE_DEBUG_SENDER_ENABLED', false),
php artisan config:set flare.flare_debug_sender true
Custom Payload Formatting:
$this->app->bind(\Spatie\FlareDebugSender\PayloadFormatter::class, function () {
return new CustomPayloadFormatter();
});
Testing Workflow:
public function testFlarePayload()
{
Flare::debug('Test payload');
$this->assertFileExists(storage_path('logs/flare-debug.log'));
}
Log File Overwrite:
flare-debug.log) is appended to by default. Ensure your testing environment doesn’t fill up storage with redundant logs.File::put(storage_path('logs/flare-debug.log'), '');
Missing Config Key:
config/flare.php, payloads will silently fail to log.'senders':
'senders' => [
\Spatie\FlareDebugSender\FlareDebugSender::class,
],
Payload Size Limits:
Flare::debug()->withData(['key' => 'value']) sparingly or sanitize data:
Flare::debug('Large data', ['user' => collect($user)->only(['id', 'name'])]);
Race Conditions in Testing:
$this->artisan('config:set flare.flare_debug_sender_log=storage/logs/test-flare.log');
Verify Sender Registration:
php artisan flare:debug
Log Format Inspection:
jsonlint.com to validate the output if issues arise.Environment-Specific Config:
'flare_debug_sender' => app()->environment('local'),
Custom Log Path:
'flare_debug_sender_log' => storage_path('logs/custom-flare-debug.log'),
Custom Payload Formatter:
Spatie\FlareDebugSender\Contracts\PayloadFormatter to modify payload structure:
class CustomFormatter implements PayloadFormatter {
public function format(array $payload): string
{
return json_encode($payload, JSON_PRETTY_PRINT);
}
}
Pre-Send Hooks:
$this->app->afterResolving(\Spatie\FlareDebugSender\FlareDebugSender::class, function ($sender) {
$sender->setPayloadModifier(function ($payload) {
$payload['custom_key'] = 'intercepted';
return $payload;
});
});
Log to External Services:
class SlackFlareDebugSender extends FlareDebugSender {
public function send(array $payload)
{
parent::send($payload);
$this->notifySlack($payload);
}
protected function notifySlack(array $payload)
{
// Slack API logic here
}
}
How can I help you explore Laravel packages today?