Skip to content

How-to guide

How to set a log retention policy

Keeping every log forever is expensive and risky; deleting too soon leaves you blind. A written retention policy settles it per data type.

4 min read10 sectionsUpdated

On this page

Key points

  • Different data, different retention: debug logs, audit logs and metrics have different value over time.
  • Most debugging uses the last 7 to 14 days.
  • Security and compliance may require months or years for specific logs.
  • Personal data in logs shortens how long you should keep them.

A sample policy

DataHot (searchable)ArchiveWhy
Application logs (info, warn, error)14 to 30 daysOptional, 90 daysDebugging and incident reviews
Debug logs1 to 3 days, or offNoneHigh volume, short value
Access logs30 days1 year (if required)Security investigations
Audit logs (who changed what)1 yearPer regulationCompliance and accountability
Traces7 to 15 daysNoneDebugging recent behaviour
Metrics13 monthsDownsampledYear-over-year comparison
Uptime check history13 monthsNoneSLA reporting

What decides the numbers

  • Debugging: how far back do incident reviews and bug reports usually look? Mostly days to weeks.
  • Security: incident responders often need weeks or months of access and authentication logs.
  • Compliance: frameworks and laws may set minimums for some logs and maximums for personal data. Check what applies to you.
  • Cost: storage and indexing grow with volume times days.
  • Privacy: the less personal data you keep, and the shorter, the lower the risk.

Reduce before you retain

Cutting volume is cheaper than shortening retention: drop health-check access logs, sample debug logs, remove duplicate lines, and keep only the fields you search. Never log secrets; mask personal data. See log levels and log aggregation.

In VitalRix

Usage controls let you keep logs, spans, metrics, RUM data and check history for fewer days than your plan allows, with the plan maximum shown next to each field, set daily caps per data type, and see a day-by-day usage table so you know which type drives cost. The audit log records sensitive changes and can be exported as CSV.

Writing the policy down

A retention policy is one page: a table like the one above, the reason for each period, who owns it, and how deletion happens (automatically, in the logging tool). Review it once a year, and whenever a new regulation, customer contract or data type appears. Auditors and enterprise customers often ask for exactly this document.

Estimating cost

Volume per day × retention days ≈ data stored. A service writing 5 GB of logs a day kept for 30 days holds about 150 GB. Cutting debug logs and health-check noise by 40% saves as much as cutting retention from 30 to 18 days, without losing any history.

Frequently asked questions

How long does GDPR say to keep logs?

GDPR does not set a fixed period. It requires keeping personal data no longer than necessary for its purpose. Define and document the purpose and period for each log type.

Should I archive logs to cheap storage?

If you have a requirement to keep them, yes: archive to object storage, compressed, with restricted access. If not, deleting is cheaper and safer.

  • Nginx monitoring: status, logs and alerts: Monitor Nginx with stub_status and JSON access logs: active and dropped connections, request rate, 5xx share, upstream time and alerts to set.
  • How to set up an on-call rotation: Set up on-call step by step: who is in it, rotation length, handoff time, layers for business hours and nights, overrides, escalation and fair compensation.
  • MySQL slow query log: how to enable and read it: Enable the MySQL slow query log without a restart, choose a sensible threshold, summarise it with mysqldumpslow and pt-query-digest, and fix what it finds.
  • Log management: Centralized log management: send structured logs over HTTPS, search and filter them, watch them live, parse with pipelines and open the trace behind a line.
  • What is telemetry?: Telemetry in software explained: the data applications emit about themselves, the main types, how it is collected and sent, and what to keep out of it.
  • What is an escalation policy?: Escalation policies explained: steps, targets and acknowledgement timeouts, an example three-step policy, repeat rules and how to avoid alerts nobody owns.

Watch your own site and services with VitalRix

Uptime checks, APM, logs, real-user monitoring, alerts and status pages in one place. Every product has a free tier and no credit card is needed.