eheuristic / laravel-log-monitor
Monitor Laravel daily log files and send error notifications via email
Requires
- php: ^7.3|^8.0|^8.1|^8.2|^8.3
- illuminate/console: ^8.0|^9.0|^10.0|^11.0
- illuminate/mail: ^8.0|^9.0|^10.0|^11.0
- illuminate/support: ^8.0|^9.0|^10.0|^11.0
Requires (Dev)
- phpunit/phpunit: ^9.0|^10.0
This package is auto-updated.
Last update: 2026-06-18 11:25:53 UTC
README
A comprehensive Laravel package that monitors daily log files and sends beautiful email notifications when errors are detected. Perfect for keeping your development and production teams informed about application health.
✨ Features
- 📧 Multiple Recipients - Send reports to unlimited email addresses
- 🔍 Smart Error Detection - Monitors emergency, alert, critical, and error levels
- 📊 Beautiful HTML Emails - Professional email template with error details and stack traces
- 📎 Log File Attachments - Automatically attaches log files (with configurable size limits)
- ⏰ Flexible Scheduling - Run daily, hourly, or on custom schedules
- ⚙️ Highly Configurable - Extensive configuration options
- 🎯 Conditional Sending - Only send emails when errors are found (configurable)
- 🔄 Laravel 8-11 Compatible - Works seamlessly across all modern Laravel versions
- 💪 Production Ready - Battle-tested error handling and logging
📋 Requirements
- PHP 7.3 or higher
- Laravel 8.x, 9.x, 10.x, or 11.x
- Configured mail driver (SMTP, Mailgun, SES, etc.)
🚀 Installation
Step 1: Install via Composer
composer require eheuristic/laravel-log-monitor
Step 2: Publish Configuration
php artisan vendor:publish --tag=log-monitor-config
This creates config/log-monitor.php.
Step 3: Configure Environment Variables
Add to your .env file:
LOG_MONITOR_ENABLED=true LOG_MONITOR_RECIPIENTS=admin@example.com,dev@example.com,support@example.com LOG_MONITOR_ONLY_ERRORS=true LOG_MONITOR_FROM_ADDRESS=noreply@example.com LOG_MONITOR_FROM_NAME="Laravel Log Monitor"
Important: Replace email addresses with your actual recipients!
Step 4: Schedule the Command
Add to app/Console/Kernel.php:
protected function schedule(Schedule $schedule) { // Send yesterday's log report daily at 1:00 AM $schedule->command('log:send-report') ->dailyAt('01:00') ->timezone('Asia/Kolkata'); // Adjust to your timezone }
Step 5: Set Up Cron (Production)
Add to your server's crontab:
* * * * * cd /path-to-your-project && php artisan schedule:run >> /dev/null 2>&1
📖 Usage
Manual Command Execution
Send yesterday's report:
php artisan log:send-report
Send report for a specific date:
php artisan log:send-report --date=2025-01-22
Force send even if no errors found:
php artisan log:send-report --force
Testing the Package
- Generate test errors:
php artisan tinker
use Illuminate\Support\Facades\Log; Log::error('Test error message'); Log::critical('Critical test error'); Log::emergency('Emergency test error'); exit
- Send test report:
php artisan log:send-report --date=2025-01-23 --force
- Check your email! 📬
⚙️ Configuration
Edit config/log-monitor.php to customize:
Basic Configuration
'enabled' => true, // Enable/disable monitoring 'recipients' => env('LOG_MONITOR_RECIPIENTS', ''), // Email addresses 'send_only_on_errors' => true, // Only send when errors exist
Log Levels to Monitor
'monitor_levels' => [ 'emergency', 'alert', 'critical', 'error', // Add 'warning', 'notice', 'info', 'debug' if needed ],
Email Customization
'subject_template' => '[{app_name}] Log Report - {date} ({error_count} errors)', 'max_file_size_mb' => 10, // Max attachment size
📧 Email Template
The package includes a beautiful, responsive HTML email template featuring:
- Summary Section - Total errors and breakdown by level
- Error Details - Color-coded error levels with timestamps
- Stack Traces - Full stack traces for debugging
- File Information - Log file path and size
- Smart Truncation - Shows top 20 errors, notes if more exist
Customizing the Email Template
Publish the views:
php artisan vendor:publish --tag=log-monitor-views
Edit: resources/views/vendor/log-monitor/emails/log-report.blade.php
🔧 Advanced Usage
Custom Scheduling
// Hourly reports $schedule->command('log:send-report')->hourly(); // Every 6 hours $schedule->command('log:send-report')->everySixHours(); // Multiple times per day $schedule->command('log:send-report')->dailyAt('09:00'); $schedule->command('log:send-report')->dailyAt('17:00'); // Weekdays only $schedule->command('log:send-report')->dailyAt('09:00')->weekdays();
Queue Support
For large log files, use queues:
// In your scheduler $schedule->command('log:send-report')->dailyAt('01:00')->runInBackground();
Custom Log Paths
// In config/log-monitor.php 'log_path' => storage_path('custom-logs'),
🌍 Timezone Configuration
Common timezone settings:
// India ->timezone('Asia/Kolkata') // US Eastern ->timezone('America/New_York') // US Pacific ->timezone('America/Los_Angeles') // UK ->timezone('Europe/London') // UTC ->timezone('UTC')
🔍 How It Works
- Scheduled Execution - Laravel's task scheduler runs the command at the configured time
- Log Analysis - The package analyzes the previous day's log file
- Error Extraction - Extracts errors matching configured log levels with full stack traces
- Conditional Check - Determines if email should be sent based on configuration
- Email Generation - Creates beautiful HTML email with error details
- Multi-Recipient Send - Sends to all configured email addresses
- Optional Attachment - Attaches log file if size is within limits
Timeline Example:
- Jan 23 - Your app generates logs →
laravel-2025-01-23.log - Jan 24 at 1:00 AM - Command runs and analyzes Jan 23 logs
- Jan 24 at 1:00 AM - Email sent to all recipients with Jan 23 errors
🛠️ Troubleshooting
No emails received?
- Test mail configuration:
php artisan tinker
Mail::raw('Test', function($msg) { $msg->to('test@example.com')->subject('Test'); });
- Check recipients: Verify
LOG_MONITOR_RECIPIENTSin.env - Check log file exists:
ls -lh storage/logs/ - Run manually with force:
php artisan log:send-report --force - Check Laravel logs:
tail -f storage/logs/laravel-*.log
Scheduler not running?
- Verify cron:
crontab -l - List scheduled tasks:
php artisan schedule:list - Test manually:
php artisan schedule:run - Check timezone: Ensure timezone matches your server
Log file not found?
- Check logging configuration: Review
config/logging.php - Verify daily channel: Ensure using 'daily' or 'stack' with daily
- Check permissions:
chmod -R 775 storage/logs
📊 Configuration Reference
| Option | Type | Default | Description |
|---|---|---|---|
enabled |
boolean | true |
Enable/disable monitoring |
recipients |
string | '' |
Comma-separated emails |
log_path |
string | storage/logs |
Log directory path |
monitor_levels |
array | See config | Log levels to monitor |
send_only_on_errors |
boolean | true |
Send only if errors exist |
date_format |
string | Y-m-d |
Log file date format |
subject_template |
string | See config | Email subject template |
max_file_size_mb |
integer | 10 |
Max attachment size (MB) |
from_address |
string | MAIL_FROM_ADDRESS |
Sender email |
from_name |
string | MAIL_FROM_NAME |
Sender name |
🤝 Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
📄 License
This package is open-sourced software licensed under the MIT license.
🙏 Credits
Developed with ❤️ for Laravel developers who want to stay informed about their application's health.
📞 Support
- Issues: GitHub Issues
- Email:
- Documentation: Full Documentation
🔗 Related Packages
- Laravel Telescope - For development debugging
- Sentry for Laravel - For production error tracking
- Laravel Log Viewer - Web-based log viewer
Star ⭐ this repository if you find it helpful!