Skip to content

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

  1. View Logs
  2. Clear Logs
  3. Log Rotation
  4. Artisan Log Commands
  5. Troubleshooting

View Logs

View Main Laravel Log (Real-time)

bash
tail -f /var/www/html/storage/logs/laravel.log

View Last 100 Lines

bash
tail -n 100 /var/www/html/storage/logs/laravel.log

View Last 500 Lines

bash
tail -n 500 /var/www/html/storage/logs/laravel.log

Search for Errors

bash
grep -i "error" /var/www/html/storage/logs/laravel.log | tail -50

Search for Specific Text

bash
grep "username" /var/www/html/storage/logs/laravel.log
grep "Exception" /var/www/html/storage/logs/laravel.log | tail -20

View with Line Numbers

bash
cat -n /var/www/html/storage/logs/laravel.log | tail -100

View 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.log

View 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.log

Clear 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.log

Clear 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/*.log

Clear 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 -delete

Clear Logs Using Artisan

bash
cd /var/www/html
php artisan logs:clear-all

Log 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/laravel

Add 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/laravel

Force Log Rotation

bash
sudo logrotate -f /etc/logrotate.d/laravel

Artisan Log Commands

Clear All Logs (Custom Command)

bash
cd /var/www/html
php artisan logs:clear-all

Clear Cache (Includes Some Logs)

bash
php artisan cache:clear
php artisan config:clear
php artisan view:clear

Clear Compiled Files

bash
php artisan clear-compiled
php artisan optimize:clear

Log Levels

Laravel logs have different severity levels:

LevelDescription
emergencySystem is unusable
alertAction must be taken immediately
criticalCritical conditions
errorError conditions
warningWarning conditions
noticeNormal but significant
infoInformational messages
debugDebug-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.log

Troubleshooting

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/logs

Log 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.log

Disk 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 -delete

Change Log Level

Edit .env:

bash
LOG_LEVEL=error

Options: debug, info, notice, warning, error, critical, alert, emergency


Quick Reference Card

ActionCommand
View live logtail -f /var/www/html/storage/logs/laravel.log
View last 100 linestail -n 100 /var/www/html/storage/logs/laravel.log
Search errorsgrep "error" /var/www/html/storage/logs/laravel.log
Clear main logsudo truncate -s 0 /var/www/html/storage/logs/laravel.log
Clear all logssudo truncate -s 0 /var/www/html/storage/logs/*.log
Delete old logsfind /var/www/html/storage/logs -name "*.log" -mtime +7 -delete
Check log sizesdu -sh /var/www/html/storage/logs/*
Fix permissionssudo chown -R www-data:www-data /var/www/html/storage/logs
Artisan clearphp artisan logs:clear-all

www.onezeroart.com