Appearance
Laravel Log Commands
Laravel generates various log files for debugging and monitoring. These commands help you manage application logs.
🟡 LOW RISK
Log management commands are generally safe. Clearing logs only removes historical data, not application functionality.
Table of Contents
View Logs
View Main Laravel Log (Real-time)
bash
tail -f /var/www/html/storage/logs/laravel.logView Last 100 Lines
bash
tail -n 100 /var/www/html/storage/logs/laravel.logView Last 500 Lines
bash
tail -n 500 /var/www/html/storage/logs/laravel.logSearch for Errors
bash
grep -i "error" /var/www/html/storage/logs/laravel.log | tail -50Search for Specific Text
bash
grep "username" /var/www/html/storage/logs/laravel.log
grep "Exception" /var/www/html/storage/logs/laravel.log | tail -20View with Line Numbers
bash
cat -n /var/www/html/storage/logs/laravel.log | tail -100View Daily Logs
bash
# List all log files
ls -la /var/www/html/storage/logs/
# View specific date
tail -f /var/www/html/storage/logs/laravel-2025-03-08.logView Channel-Specific Logs
bash
# Queue worker logs
tail -f /var/www/html/storage/logs/worker.log
# Daily quota logs
tail -f /var/www/html/storage/logs/daily_quota.log
# Weekly quota logs
tail -f /var/www/html/storage/logs/weekly_quota.log
# CoA logs
tail -f /var/www/html/storage/logs/CoA/coa.log
# Graph logs
tail -f /var/www/html/storage/logs/graph/subscriber/graph-subscriber.logClear Logs
Clear Main Laravel Log
🟠 CAUTION
This removes all log history. Consider backing up first if needed for debugging.
bash
# Truncate (clear content, keep file)
sudo truncate -s 0 /var/www/html/storage/logs/laravel.log
# Or using echo
sudo echo "" > /var/www/html/storage/logs/laravel.logClear All Log Files
bash
# Clear all .log files in storage/logs
sudo truncate -s 0 /var/www/html/storage/logs/*.log
# Or remove and let Laravel recreate
sudo rm /var/www/html/storage/logs/*.logClear Old Daily Logs
bash
# Remove logs older than 7 days
find /var/www/html/storage/logs -name "*.log" -mtime +7 -delete
# Remove logs older than 30 days
find /var/www/html/storage/logs -name "*.log" -mtime +30 -deleteClear Logs Using Artisan
bash
cd /var/www/html
php artisan logs:clear-allLog Rotation
Check Log File Sizes
bash
du -sh /var/www/html/storage/logs/*
du -sh /var/www/html/storage/logs/Setup Log Rotation (logrotate)
bash
sudo nano /etc/logrotate.d/laravelAdd configuration:
/var/www/html/storage/logs/*.log {
daily
missingok
rotate 14
compress
delaycompress
notifempty
create 0664 www-data www-data
sharedscripts
}Test Log Rotation
bash
sudo logrotate -d /etc/logrotate.d/laravelForce Log Rotation
bash
sudo logrotate -f /etc/logrotate.d/laravelArtisan Log Commands
Clear All Logs (Custom Command)
bash
cd /var/www/html
php artisan logs:clear-allClear Cache (Includes Some Logs)
bash
php artisan cache:clear
php artisan config:clear
php artisan view:clearClear Compiled Files
bash
php artisan clear-compiled
php artisan optimize:clearLog Levels
Laravel logs have different severity levels:
| Level | Description |
|---|---|
emergency | System is unusable |
alert | Action must be taken immediately |
critical | Critical conditions |
error | Error conditions |
warning | Warning conditions |
notice | Normal but significant |
info | Informational messages |
debug | Debug-level messages |
Filter by Log Level
bash
# Only errors
grep "\[error\]" /var/www/html/storage/logs/laravel.log
# Only warnings and above
grep -E "\[(error|critical|alert|emergency)\]" /var/www/html/storage/logs/laravel.logTroubleshooting
Log File Not Writable
bash
# Fix permissions
sudo chown -R www-data:www-data /var/www/html/storage/logs
sudo chmod -R 775 /var/www/html/storage/logsLog File Too Large
bash
# Check size
du -sh /var/www/html/storage/logs/laravel.log
# Truncate if too large
sudo truncate -s 0 /var/www/html/storage/logs/laravel.log
# Or compress and archive
gzip -c /var/www/html/storage/logs/laravel.log > /backup/laravel-$(date +%Y%m%d).log.gz
sudo truncate -s 0 /var/www/html/storage/logs/laravel.logDisk Full Due to Logs
bash
# Find largest log files
find /var/www/html/storage/logs -type f -exec du -h {} + | sort -rh | head -20
# Clear old logs
find /var/www/html/storage/logs -name "*.log" -mtime +7 -deleteChange Log Level
Edit .env:
bash
LOG_LEVEL=errorOptions: debug, info, notice, warning, error, critical, alert, emergency
Quick Reference Card
| Action | Command |
|---|---|
| View live log | tail -f /var/www/html/storage/logs/laravel.log |
| View last 100 lines | tail -n 100 /var/www/html/storage/logs/laravel.log |
| Search errors | grep "error" /var/www/html/storage/logs/laravel.log |
| Clear main log | sudo truncate -s 0 /var/www/html/storage/logs/laravel.log |
| Clear all logs | sudo truncate -s 0 /var/www/html/storage/logs/*.log |
| Delete old logs | find /var/www/html/storage/logs -name "*.log" -mtime +7 -delete |
| Check log sizes | du -sh /var/www/html/storage/logs/* |
| Fix permissions | sudo chown -R www-data:www-data /var/www/html/storage/logs |
| Artisan clear | php artisan logs:clear-all |
