Log retention

Also known as: log retention policy

On this page 7

Log retention is the defined period and set of rules for how long log data is stored, where it is kept during that period, and how it is archived or deleted when the period ends. In monitoring & logs for servers, a log retention policy balances three competing needs: operational troubleshooting, security investigations and compliance, and the cost and privacy risk of keeping data longer than necessary.

Retention is distinct from log rotation. Rotation splits growing files into manageable pieces on a single host, while retention decides how long those pieces, and their copies in central systems, must survive. A rotation setting of fourteen files can therefore coexist with a retention requirement of one year in an archive.

How a log retention policy is structured

A complete policy states, for each log category, a minimum retention period, a maximum retention period, the storage tier for each phase, the access controls, and the disposal method. The minimum protects the ability to investigate incidents and satisfy auditors; the maximum limits privacy exposure and storage cost.

Most organizations implement retention as a tiered lifecycle. Recent logs sit in fast, searchable storage, older logs move to cheaper compressed storage, and the oldest move to an archive before final deletion. The following table shows a typical arrangement.

TierTypical age of dataStorage mediumQuery speed
Hot0 to 14 daysSSD-backed indexSeconds
Warm2 weeks to 3 monthsCompressed index on cheaper disksSeconds to minutes
Cold or archive3 months to several yearsObject storage, often immutableMinutes to hours after restore
DeletedAfter the maximum periodSecurely erasedNot available
Typical storage tiers in a retention lifecycle

Tools such as Elasticsearch index lifecycle management, Grafana Loki retention settings, Graylog index rotation and object-storage lifecycle rules automate these transitions, so that no administrator has to delete data by hand.

Retention periods for different log types

Different logs serve different purposes, so a single global period is rarely appropriate. Debug output loses value within days, whereas authentication and audit records may be needed months later when a breach is discovered. Ranges below are common starting points, not legal advice; the binding values come from applicable law, contracts and internal risk assessment.

Log categoryTypical retention rangeMain driver
Debug and verbose logs1 to 7 daysTroubleshooting only
Application log14 to 90 daysIncident analysis
Access log30 to 180 daysTraffic analysis, abuse handling
Error log30 to 180 daysTrend and root-cause analysis
Security and authentication logs6 months to 1 year or moreBreach detection and forensics
Audit trails1 to 7 yearsRegulatory and contractual duties
Common retention ranges by log category

A practical reference point is the typical breach detection delay, which can reach several months. If security logs are deleted after thirty days, an intrusion discovered in month three cannot be reconstructed. This is why security frameworks often call for at least one year of security-relevant logs, with a shorter period immediately searchable.

Regulations influence retention from two directions: some require minimum periods, while data protection law limits how long personal data may be kept. Logs frequently contain personal data such as IP addresses, user identifiers and email addresses, so both pressures apply at once.

FrameworkEffect on retentionPractical consequence
PCI DSSAudit logs kept at least 12 monthsLast 3 months immediately available
GDPRStorage limitation principleJustify and cap periods for personal data
HIPAASix-year documentation dutyLong archive for relevant audit records
ISO/IEC 27001Logging and monitoring controlsDocumented, reviewed retention policy
SOC 2Evidence of monitoring over the audit periodLogs covering the full review window
How common frameworks affect log retention

Requirements change and vary by jurisdiction and sector, so the policy should name an owner responsible for legal review. Where minimum and maximum duties conflict, common techniques are pseudonymizing identifiers after the operational period, restricting archive access, and documenting the legal basis for each category.

Implementing log retention on servers

On individual servers, retention starts with local rotation through logrotate or systemd-journald limits, which keep disks from filling. Real retention, however, depends on log aggregation: logs are shipped with agents such as Fluent Bit, Fluentd or Logstash to a central platform where lifecycle policies apply uniformly.

  • Classify every log source and assign it a category and period in a written policy.
  • Ship logs off the host quickly, because a compromised server may have its local logs erased.
  • Store archives immutably with write-once object storage or Object Lock for evidential value.
  • Compress and reduce by dropping noisy fields and sampling verbose debug data.
  • Support legal holds that suspend deletion for data relevant to litigation or investigations.
  • Verify deletion and restore regularly, including a test query against archived data.

Storage cost grows linearly with ingest volume and retention length. A platform ingesting 200 GB per day with ninety days of hot retention must hold roughly 18 TB before replication, which is why tiering and field filtering usually matter more than hardware choice.

Common mistakes in log retention

Many retention failures are discovered only during an incident or audit, when the needed data no longer exists or should not exist. The table summarizes frequent problems.

MistakeConsequenceFix
Rotation mistaken for retentionLogs vanish after a few daysCentral archive with defined periods
Keeping everything foreverHigh cost and privacy exposureMaximum periods per category
Logs only on the source hostAttackers erase evidenceReal-time forwarding to a separate system
Unreadable archivesOld formats or lost keys block restoresPeriodic restore tests
No clock synchronizationEvents cannot be correlatedNTP on every server
Retention mistakes and their fixes

A plain-language summary

Log retention is a decision about how long to keep the records that servers write about what they do. Those records help fix problems and investigate break-ins, but they also take space and may contain information about people.

A good policy works like a filing system for receipts. Recent ones stay in a drawer. Older ones go into a box in the attic. Everything is shredded once it is no longer needed.

An example from practice

A payment processing company operates forty Linux servers and must meet PCI DSS. Its earlier setup kept logs only on each server with seven days of rotation. When a suspicious login was reported two months after it happened, the team found that no authentication records remained, and the investigation stalled.

The company then introduced a written log retention policy. Fluent Bit forwards logs within seconds to a central Graylog cluster, which keeps ninety days hot and searchable. Older data moves to object storage with Object Lock for twelve months, after which lifecycle rules delete it. Debug logs are kept for three days only, and IP addresses in access logs are pseudonymized after thirty days. At the next audit, the team retrieved a ten-month-old authentication event within one hour, and the assessor accepted the documented retention evidence without findings.