Log Management
Comprehensive log management strategy for Netasampark.
Log Channels
Application Logs
- Storage:
storage/logs/laravel.log - Level: INFO, WARNING, ERROR
- Rotation: Daily
- Retention: 30 days
Access Logs
- Storage: Web server logs
- Format: Combined log format
- Rotation: Daily
- Retention: 90 days
Error Logs
- Storage:
storage/logs/error.log - Level: ERROR, CRITICAL
- Rotation: Daily
- Retention: 90 days
Security Logs
- Storage:
storage/logs/security.log - Level: All security events
- Rotation: Daily
- Retention: 365 days
Log Configuration
Laravel Logging
// config/logging.php
'channels' => [
'daily' => [
'driver' => 'daily',
'path' => storage_path('logs/laravel.log'),
'level' => env('LOG_LEVEL', 'debug'),
'days' => 30,
],
'security' => [
'driver' => 'daily',
'path' => storage_path('logs/security.log'),
'level' => 'info',
'days' => 365,
],
],
Log Levels
DEBUG
- Detailed debugging information
- Development only
- Not logged in production
INFO
- General informational messages
- Application flow
- User actions
WARNING
- Warning messages
- Recoverable errors
- Deprecated features
ERROR
- Error messages
- Exceptions
- Failed operations
CRITICAL
- Critical errors
- System failures
- Immediate attention required
Log Aggregation
ELK Stack
- Elasticsearch: Log storage and search
- Logstash: Log processing
- Kibana: Visualization
Setup
# docker-compose.yml
version: '3'
services:
elasticsearch:
image: elasticsearch:8.0.0
logstash:
image: logstash:8.0.0
kibana:
image: kibana:8.0.0
Log Rotation
Automatic Rotation
# logrotate configuration
/var/www/storage/logs/*.log {
daily
rotate 30
compress
delaycompress
notifempty
create 0640 www-data www-data
sharedscripts
postrotate
php artisan queue:restart
endscript
}
Log Analysis
Common Queries
# Error count
grep -c "ERROR" laravel.log
# Errors by date
grep "ERROR" laravel.log | cut -d' ' -f1 | sort | uniq -c
# Recent errors
tail -n 100 laravel.log | grep "ERROR"
Best Practices
- Structured Logging: Use JSON format
- Context Information: Include request ID, user ID
- Sensitive Data: Never log passwords, tokens
- Log Levels: Use appropriate levels
- Rotation: Regular log rotation
- Monitoring: Monitor log file sizes
- Retention: Clear retention policy