laravel/pail
Laravel Pail tails your Laravel app’s logs in a sleek, interactive CLI. Works with any log driver (including Sentry and Flare) and includes handy filters to quickly find the messages you need while developing.
Installation:
composer require laravel/pail --dev
(Note: Pail is automatically suggested as a dev dependency in Laravel 11+ via PR #56.)
First Use Case: Tail all logs in real-time:
php artisan log:tail
(Press Ctrl+C to exit.)
Key Flags for Immediate Use:
php artisan log:tail --level=error
php artisan log:tail --context=auth
php artisan log:tail --lines=100
php artisan log:tail --timeout=30
Where to Look First:
php artisan log:tail --help
(Lists all available options, including --since, --until, and --driver.)Debugging Workflow:
php artisan log:tail --level=error --context=payment
? for help, q to quit) to interactively refine filters.CI/CD Pipeline:
php artisan log:tail --timeout=60 --level=critical
set +e if needed):
if php artisan log:tail --timeout=30 --level=error | grep -q "Fatal"; then
exit 1
fi
Production Monitoring:
php artisan log:tail --driver=single --since="1 hour ago"
--driver=single for non-default log drivers like Sentry/Flare.)Custom Log Drivers:
php artisan log:tail --driver=sentry
flare log driver is configured in config/logging.php.Multiline Logs:
Log Context:
--context to filter logs by arbitrary context data (e.g., user_id, request_id):
php artisan log:tail --context="user_id=123"
context array in your log messages.)Time-Based Filtering:
php artisan log:tail --since="2024-01-01" --until="2024-01-02"
php artisan log:tail --since="-5 minutes"
Combining with Other Tools:
grep or jq for further processing:
php artisan log:tail --level=debug | grep "database"
php artisan log:tail --level=info | jq '.context.request_id'
Automated Testing:
--timeout to test log output in isolated environments:
php artisan log:tail --timeout=10 --level=warning
$this->artisan('log:tail --timeout=5 --level=error')
->expectsOutputToContain('Expected error message');
Dynamic Filtering:
--interactive to dynamically adjust filters without restarting the command:
php artisan log:tail --interactive
(Press f to filter, then type your query.)Log Archiving:
php artisan log:tail --timeout=300 --level=info > app_logs.txt
Custom Commands:
log:tail with project-specific defaults:
// app/Console/Commands/TailPaymentLogs.php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Symfony\Component\Process\Process;
class TailPaymentLogs extends Command
{
protected $signature = 'logs:payments';
protected $description = 'Tail payment-related logs';
public function handle()
{
$process = new Process(['php', 'artisan', 'log:tail', '--level=error', '--context=payment']);
$process->run(function ($type, $output) {
$this->output->write($output);
});
}
}
Malformed JSON Logs:
try-catch in your logging code:
try {
Log::error('Malformed log', ['context' => 'data']);
} catch (\Exception $e) {
Log::error("Failed to log: {$e->getMessage()}");
}
Auth User Resolution Overhead:
--context with auth-related data or upgrade to v1.2.7+.Multiline Log Parsing:
--driver=single for file-based logs to ensure proper multiline handling.Timezone Mismatches:
--since/--until with UTC timestamps or set the TZ environment variable:
TZ=UTC php artisan log:tail --since="2024-01-01T00:00:00"
Non-Text Log Drivers:
single, daily, sentry, flare).Deprecation Warnings:
Check Log Driver Configuration:
config/logging.php has the correct default driver:
'default' => env('LOG_CHANNEL', 'single'),
Inspect Raw Log Files:
tail -f storage/logs/laravel.log
Enable Debug Mode:
--verbose to see underlying issues:
php artisan log:tail --verbose
Handle Stale Log Files:
How can I help you explore Laravel packages today?