Log Retention: How Long Should You Keep Logs?
Keeping logs forever is expensive. Learn how to determine the right retention period for your logs.
Log retention is a balance between "we might need this" and "this costs money to store." Most teams either keep logs too long (expensive) or not long enough (can't debug old issues). Here's how to find the right balance.
Factors That Determine Retention
1. Debugging Windows
How quickly do issues get reported and investigated?
- Real-time monitoring: Minutes to hours
- User-reported bugs: 1-7 days
- Performance investigations: 7-30 days
- Infrequent issues: 30-90 days
2. Compliance Requirements
Some industries mandate minimum retention:
- PCI DSS: 1 year
- HIPAA: 6 years
- SOX: 7 years
- GDPR: Minimize (shortest period necessary)
3. Cost Sensitivity
Longer retention = higher costs. Calculate the trade-off:
100GB/month × 30 days = 100GB stored
100GB/month × 90 days = 300GB stored (3× cost)
Recommended Retention by Log Type
| Log Type | Suggested Retention | Rationale |
|---|---|---|
| Error/Critical | 30-90 days | Debugging infrequent issues |
| Warning | 14-30 days | Trend analysis |
| Info | 7-14 days | Recent context |
| Debug | 1-3 days | Active debugging only |
| Audit logs | 1-7 years | Compliance |
| Security events | 90 days - 1 year | Investigation |
Tiered Retention Strategy
Use different storage tiers for different ages:
Days 1-7: Hot storage (fast search)
Days 8-30: Warm storage (slower, cheaper)
Days 31-90: Cold storage (archive)
90+ days: Delete or archive to cheap object storage
Implementation Example
// config/logging.php
'clicks' => [
'driver' => 'custom',
'retention' => [
'error' => 30, // 30 days
'warning' => 14,
'info' => 7,
'debug' => 3,
],
],
Questions to Ask
- When was the last time you searched logs older than 30 days?
- Do you have compliance requirements mandating retention?
- What's the cost per GB for your log storage?
- Can you recreate old logs from other sources if needed?
Practical Approach
- Start short: Begin with 7-day retention
- Track access patterns: How often do you search old logs?
- Extend as needed: If you frequently need older logs, extend
- Separate compliance logs: Keep audit trails separate with longer retention
Conclusion
Most teams keep logs longer than necessary. Start with shorter retention, measure your actual needs, and adjust. You can always increase retention—but you can't recover deleted logs.
The sweet spot for most applications: 7-30 days for operational logs, longer for audit and security.
Admin
Published on December 4, 2025