Quick revision
The short answer
I would start by classifying logs instead of setting one retention for all: operational debugging logs, security and audit events, and business records each have different legal and retention needs. Records that legal needs for a year should not live in debug logs at all; they move to an audit store with a schema, access control and one-year retention, while operational logs get short hot retention, for example 7 to 30 days, cheaper archive tiers only if needed and no personal data by design. Cost falls through dropping DEBUG and sampling noisy INFO, levels per environment and charging volume back to teams, and the whole policy is written with legal and security, with deletion implemented in the platform and tested, including legal holds.
What to remember
In this answer, we resolved three conflicting demands by classifying logs into operational logs, security and audit events, and business records. Records needed for a year moved to an audit store with a schema, access control and its own retention, operational logs got short hot retention with no personal data by design, and cost fell through lower production levels, sampling of noisy categories, per-environment settings, shorter hot tiers and volume charged back to teams. The policy was written with legal and security, deletion was automated in the platform, and both deletion and legal holds were tested.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
I would start by classifying logs instead of setting one retention for all: operational debugging logs, security and audit events, and business records each have different legal and retention needs. Records that legal needs for a year should not live in debug logs at all; they move to an audit store with a schema, access control and one-year retention, while operational logs get short hot retention, for example 7 to 30 days, cheaper archive tiers only if needed and no personal data by design. Cost falls through dropping DEBUG and sampling noisy INFO, levels per environment and charging volume back to teams, and the whole policy is written with legal and security, with deletion implemented in the platform and tested, including legal holds.
Why this question is asked
This question has three stakeholders with demands that look incompatible: keep for a year, delete after 30 days, and spend half as much. A junior answer picks one of them or splits the difference; a senior answer sees that the conflict exists only because three different kinds of data share one pipeline. Interviewers ask it to see whether we can reframe a policy dispute into a design, and then carry it through to implementation and proof. In this answer, we will recap why one retention period fails, classify the logs, design a home for each class, cut cost, write the policy with the stakeholders, and test that deletion and holds really work.
1Why One Retention Period Cannot Work
Today all application logs go to one store with one retention period. If we keep everything for a year to satisfy legal, we keep personal data for a year, breaking security's rule and probably data protection law, and we pay to store a year of DEBUG lines. If we delete everything after 30 days, we lose the records legal needs. Any compromise in between fails both.
The way out is to notice that legal does not need a year of debug logs. Legal needs certain events, such as who approved a payment or when a customer accepted terms, and those events happen to be in the logs today because that was the easiest place to write them.
2Classifying the Logs
We sort log data into three classes. Operational logs are what engineers use to debug and operate services: request errors, retries, stack traces. They are valuable for days or weeks. Security and audit events record who did what: logins, permission changes, access to sensitive records, admin actions. Business records are events with legal or financial meaning, such as an order confirmation, a consent change or a payment approval, which in a well-designed system also exist in a database.
| Class | Who needs it | Retention | Personal data |
|---|---|---|---|
| Operational logs | engineers, on-call | 7 to 30 days hot | none by design; masked |
| Security and audit events | security, auditors | 1 year or as regulated | only what is required, access controlled |
| Business records | legal, finance | per legal requirement | as required, in a proper store |
3A Home for Each Class
Audit and business records that must be kept for a year move out of the debug logs into an audit store. Services write them through a small audit library with a defined schema, for example actor, action, target, time, outcome and reason, to a durable destination with proper delivery guarantees, not a best-effort log pipeline. The store has strict access control, its own one-year retention, and only the personal data the record truly needs, perhaps a customer id rather than a name and address.
Operational logs then become easy. They keep 7 to 30 days in the hot, searchable tier, depending on how far back teams really search; most queries are about the last few days. If some teams need longer for trend analysis, an archive tier in cheap object storage can keep compressed logs for 90 days. And personal data is kept out by design: the shared logging starter masks known fields such as email and card numbers, code review checks for personal data in log statements, and a scanner in the pipeline flags patterns that slip through. With no personal data in operational logs, security's 30-day rule is easy to meet, because it becomes a rule about the rare exceptions.
- Does it record who did what, or a legal or financial fact?YesWrite through the audit libraryNoIt is an operational log
- Audit storeschema, access control, 1 year retention
- Does the operational log contain personal data?YesMask in the starter; fix the codeNoSend to the log pipeline
- Operational store7 to 30 days hot, optional archive tier
4 steps in order. Play them, or step through them one at a time.
4Cutting the Cost in Half
With the classes separated, cost becomes a question of operational log volume. In most companies, most volume comes from a few sources: DEBUG left on in production, INFO lines per request that only count things metrics already count, and repeated stack traces from one noisy failure. So the measures are concrete. Production runs at INFO by default, with DEBUG enabled per logger and per period when needed. Noisy INFO categories, such as access logs on health checks, are sampled or dropped in the shipper. Levels differ per environment, so test environments can be verbose and keep data for only three days.
The strongest lever is visibility. Each team sees its own log volume and cost in a monthly report, and volume above its budget triggers an alert. Once teams can see that one logger costs as much as an engineer's salary, they fix it. Shorter hot retention also cuts storage directly: moving from 90 days to 14 days hot, with a cheap archive behind, can by itself cut storage cost substantially. Together these usually reach a 50 percent reduction, and we measure monthly to confirm.
5Writing the Policy and Proving It Works
The policy is written together with legal and security, not handed to them, because each needs to confirm that their requirement is met by the right class. It names the classes, their stores, retention periods, who can access each, how personal data is handled, and who owns each part. It also covers legal holds: the process by which legal can stop deletion of specific data during an investigation or lawsuit.
Then we implement deletion in the platform rather than relying on people. Retention is set as index or bucket lifecycle rules, so data older than the limit is deleted automatically. And we test it, because an untested deletion policy is only a hope: a scheduled check confirms that no operational data older than the limit exists, that audit data older than a year is gone unless held, and that a test hold really prevents deletion. Auditors will ask for this evidence, and it is much easier to show a report than to explain.
6Follow-up questions
How do you handle a legal hold on logs that are due for deletion?
Legal raises a hold with a scope, such as these customers or these services between two dates, and the platform team applies it before the data expires: either by copying the matching data into a held location with its own retention, or by tagging it so lifecycle rules skip it. The hold is recorded with an owner and a review date, and when legal releases it, normal deletion resumes. The key is that the hold process exists and is tested before the first real lawsuit, because during one there is no time to invent it.
What if engineers say they need operational logs for longer than 30 days?
Ask what they actually do with old logs. Usually it is trend analysis or comparing behaviour with last quarter, which metrics answer better and more cheaply. For the rare deep investigation, a compressed archive tier can keep logs longer at low cost, as long as they contain no personal data.
Is it enough to mask personal data in the shipper?
It is a useful safety net but not enough by itself, because the shipper only recognises patterns it knows. The main defence is not logging personal data in the first place, through the starter's masking of known fields, code review and clear guidance, with the shipper catching what slips through.
7Conclusion
In this answer, we resolved three conflicting demands by classifying logs into operational logs, security and audit events, and business records. Records needed for a year moved to an audit store with a schema, access control and its own retention, operational logs got short hot retention with no personal data by design, and cost fell through lower production levels, sampling of noisy categories, per-environment settings, shorter hot tiers and volume charged back to teams. The policy was written with legal and security, deletion was automated in the platform, and both deletion and legal holds were tested.
Open with
I would first point out that the three demands only conflict because three different kinds of data share one pipeline. So I would classify logs: operational logs for debugging, security and audit events, and business records with legal meaning.
Then, if they want more
Legal's one-year requirement is really about specific events, like who approved a payment or a consent change, and those should not live in debug logs at all.
I would move them to an audit store written through a small audit library with a defined schema, strict access control and its own one-year retention, containing only the personal data the record needs.
Operational logs then get short hot retention, say 7 to 30 days depending on how far back teams actually search, with an optional cheap archive tier, and no personal data by design: the shared starter masks known fields, reviews check log statements, and the pipeline scans for leaks. That satisfies security.
For cost, I would run production at INFO with DEBUG enabled per logger only when needed, sample or drop noisy categories like health check access logs, use shorter retention in test environments, and give each team a volume budget with monthly cost reports, which in my experience is what really changes behaviour.
I would write the policy together with legal and security, implement deletion as lifecycle rules in the platform, define a legal hold process, and test regularly that expired data is really gone and that holds really stop deletion.
About this answer
- Last updated
- 12 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the official documentation for the version you use. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "Legal says application logs must be kept for one year for some systems, while security...": https://scrivio-interview-library.netlify.app/java/java-logging/44282caab0/