# Is longer log retention safer? That's treating a liability as an asset

Date: 2026-11-20
Category: Technology
Tags: Log Retention, Compliance, Privacy
Summary: Compliance requires logs to be retained for at least six months, and many teams interpret this as the longer the better. This article breaks down the three use cases—auditing, troubleshooting, and privacy—and provides criteria for tiered retention and concrete practices for deletion upon expiration.

A common compliance review scenario: the reviewer asks how long critical operation logs are retained, and the team answers, "Permanent retention—it's the safest." The other side follows up with one question: do the logs contain phone numbers, ID numbers, or session content? The meeting room often goes silent.

The reason this question hits the mark is that it separates two things that have been conflated. Auditing needs to know "what happened, and can it be proven"; privacy minimization needs to ensure "don't keep what shouldn't be kept." The former cares whether the evidence exists; the latter cares whether the data exists. If the team has only one concept of "logs," it can only produce one policy—and that policy is bound to fail on one side or the other.

My judgment: retention duration is not a security property; it is a risk-and-cost property. The longer you keep logs, the more you get not security, but a larger breach surface, more expensive retrieval, and a data map that is harder to explain.

## "No less than six months" was read as "the longer the better"

The most frequently cited provision in the Cybersecurity Law requires taking technical measures to monitor and record network operation status and cybersecurity incidents, and retaining network logs for no less than six months. "No less than" is a floor, not a target. But in implementation, many teams execute it as "six months is the bottom line, so keeping three years can't be wrong."

This reasoning has two flaws.

First flaw: logs are one of the places with the highest density of sensitive data. An ordinary web request log may contain IPs, User-Agents, tokens in URLs, and phone numbers in request bodies; a model invocation log may contain a user's full conversation, uploaded document snippets, or even the recognition results of ID photos. Every extra day this data is retained is another day of probability that it is queried without authorization, exported internally, mistakenly pulled into a test environment, or carried off in a backup.

Second flaw: the longer it is kept, the worse its usability. A log store is not a museum; it is a query system. Three years of data means larger indexes, more complex hot/cold tiering, and more changes in field structure. When something actually goes wrong, you need to locate those twenty minutes within three years, while many old fields have long had no one maintaining them. Retaining and being able to query are two different things.

## Logs are not one category of thing

Cramming all logs into a single retention policy is the root of this kind of problem. A real system has at least the following categories, with completely different risks and uses:

| Type | Typical content | PII density | Retention period I lean toward |
| --- | --- | --- | --- |
| Audit events | Who did what to which object and when, and the result | Low, only IDs | 180 days to 1 year |
| Business operations | Order status, configuration changes, approval flows | Medium | 90 to 180 days |
| Application debugging | Request parameters, response bodies, stack traces | High | 7 to 30 days |
| Model invocation | Prompts, model outputs, tool-call inputs | Very high | Within 7 days, or keep only summaries |
| Security logs | Logins, authentication failures, unauthorized attempts | Medium | 180 days |

The key to this table is not the specific number of days, but the differences in the last column: audit events can be kept long because their fields are actions and objects and contain no business content; model invocation logs must be kept short because they are copies of users' own words. Covering these five categories with one policy is equivalent to letting the most sensitive category determine the floor for all categories—and the result will inevitably be over-retention.

Moreover, many log systems are organized by service, not by data sensitivity. This is a natural engineering outcome: it is most convenient for services to log themselves. But to retain by tier, a layer of judgment must be added on the write side: which channel this log belongs to, whether fields need masking, and whether the original text can be written directly.

Which channel a log should go to at write time can be compressed into four judgments:

```mermaid
flowchart TD
    A[日志写入] --> B{是否含个人信息}
    B -->|是| C[写入前脱敏或哈希]
    B -->|否| D{是否审计事件}
    C --> D
    D -->|是| E[审计通道长保留]
    D -->|否| F{是否用于排障}
    F -->|是| G[调试通道短保留]
    F -->|否| H[不落盘只留指标]
```

The earliest step in this chain is masking, not retention period. Many discussions start by arguing "30 days or 90 days," but if the original text carries phone numbers, the difference between 30 and 90 days is only the length of the exposure window, not the presence or absence of risk. Only after removing fields that should not be kept on the write side does the discussion of retention period become meaningful.

## The longer logs are kept, the harder auditing becomes

This runs counter to intuition, but it is very obvious in actual troubleshooting.

As log retention time grows, noise accumulates by the day. Suppose a medium-sized service produces 200 GB of logs per day; a year is on the order of tens of TB. The main cost here is not storage fees, but indexing and querying. For cold data to be searchable, indexes must be built or archive scans used, and query latency goes from seconds to minutes. On-call staff cannot wait, so they proactively narrow the time window—and in the end they still query only data from within the past hour. The actual auditing capability brought by three years of retention may be worse than thirty days of retention plus a good retrieval system.

The second problem is structural change. Over three years, the service was refactored twice, log fields were renamed—a key field was called `uid` two years ago, later changed to `user_id`, and later still placed into a nested structure. The old logs are still there, but the query statements no longer match. In this case, "we have three years of logs" is an unverifiable statement. It is the same principle as backups: a backup that has never undergone a restore drill cannot count as a backup.

The third problem is more insidious: the more logs there are, the easier it is to bury the truly important signals. Auditing needs key events, not a full流水. If everything goes into the same pool, the auditor gets a pile of raw data that must be filtered on site, rather than an evidence chain that can be read directly.

My trade-off: I would rather make audit events narrow and deep than retain everything. Narrow means fixed fields, stable structure, and recording only actions and objects; deep means long retention, append-only and immutable, and access with approval. Only these two together constitute "auditability"; it cannot be piled up by long retention alone.

## How to delete on schedule without losing evidence

The biggest resistance to tiered retention is not technical but psychological. The business side will ask: what if a problem arises after deletion?

This concern is reasonable, but it can be broken down. What you need to retain long-term is often not the original text, but the fact that "the original text existed at the time and was not tampered with." These two can be stored separately.

One approach is evidence tiering: audit events go through an independent channel, structured and small in volume, retained for a year or even longer; raw request bodies and response bodies go through the debugging channel, retained for two weeks, and physically deleted upon expiry; for parts whose integrity must be proven, compute a hash once per day and write the hash into tamper-proof storage, delete the original text, and keep the hash. If in the future you need to prove that the logs from that day were not modified after the fact, the hash will be useful, while the user's own words are no longer in the store.

Another approach is sampled retention: model invocation logs are not written in full; they are sampled proportionally, and the sampled content is masked and used only for effectiveness analysis and badcase review. Full logs solve "what went wrong with one specific request"; sampled logs solve "what is the error rate for this type of request." Most of the time, what the product team wants is the latter.

Deletion itself must also leave traces. The execution records of deletion tasks, how many records were deleted, and which time partition was deleted must all go into the audit log and be subject to spot checks. What I have seen is this: the retention policy looks beautiful in the document, but in actual operation, because one configuration did not take effect, the log store has not deleted anything for three years. Policy compliance and execution compliance are two different things; the latter requires regular verification—for example, sampling one partition each quarter to confirm that it is really gone, rather than merely seeing an "expired" label in the console.

This part can be solidified into configuration rather than relying on people's memory:

```yaml
retention:
  audit_event:
    fields: [actor_id, action, object_id, result, ts]
    keep_days: 365
    store: append_only
  biz_operation:
    keep_days: 180
    pii_fields: hash
  app_debug:
    keep_days: 14
    drop_fields: [request_body, response_body, cookie, authorization]
  model_call:
    keep_days: 7
    mode: summary_only
  security:
    keep_days: 180
```

What really matters in this configuration is not the number of days, but the two lines `drop_fields` and `mode: summary_only`. They determine which data never enters the database in the first place. Policies written on the deletion side will always encounter moments when they fail to execute; policies written on the write side will not.

## How long a log should be kept: ask three questions first

If I were to give a reusable criterion, I would use these three questions, and the order should not be changed.

First, whose data and what data is in this log. If it contains users' own words, ID numbers, locations, or contacts, desensitize it first before discussing the retention period. Can we keep only IDs and results, and not the content?

Second, who will read it, and how often. If no one has queried a type of log within thirty days, the retention period should be recalculated. This does not mean deleting it immediately, but rather clarifying which specific scenario it is being kept for. If you cannot answer that, then by default it is being kept permanently and quietly taking up space.

Third, if the entire database leaked tomorrow, what would be the worst consequence, and could it be explained externally. This question immediately splits logs into two piles: one pile where a leak is a PR incident, and one pile where a leak is merely internal embarrassment. The former must be kept for a short time, or the original text must not be kept.

Once these three questions are answered, the retention period is basically set. The remaining work is to write it into the configuration, add it to reviews, and verify it regularly.

## When this approach does not apply

The tiering logic above has a clear boundary of applicability: it assumes that your retention obligation comes from auditing and troubleshooting, not from explicit industry regulation.

In anti-money laundering in finance, medical records in healthcare, and transaction records in some industries, regulators impose hard requirements on retention periods, and five years is a common order of magnitude. In such cases, using privacy minimization to oppose explicit regulations is unwise; compliance obligations take priority. The room for action lies elsewhere: encrypted storage, domain separation by project, two-person approval for access, export trails, and regular permission revocation. The core is that overused but true saying: retention does not mean anyone can read it. Retention periods obey regulations; readability obeys minimum necessity.

Another boundary is accountability for internal abuse of authority. If logs are the only evidence for clarifying a certain violation, deleting them too early is self-defeating. The solution here is not to extend all logs, but to separate audit events on their own, ensuring that the information "who did what to which object and when" is long enough and complete enough. Business details can be short; action records must be long.

Conversely, there is also a type of team whose problem is not keeping logs too long, but too short: when an online issue needs a postmortem, they find that key logs were kept for only three days, and the data rolled away before the incident was even located. This is another pitfall, usually because logs are treated as a pure cost item and no one is responsible for "how many days troubleshooting needs." Debug logs should at least cover a complete release cycle plus an observation window; two weeks is a relatively safe starting point.

Back to the review scenario at the beginning. Next time someone asks how long logs should be retained, do not rush to give a number. First ask: which type of log, whose data and what data is in it, and who will read it. Once these three answers are out, the retention period does not need to be argued over; it emerges on its own, and the remaining debate will only focus on things that can be decided on the spot, such as whether specific fields should be desensitized.
