Orofold Labs

Launching soon

Notes Get in touch

Operations and security 4 min read Updated

What to record in logs and how long to keep them

In short

Log the security events that help you answer what happened, keep passwords, tokens and personal data out of logs, and protect the logs you keep.

Logs answer the question of what happened, often long after the event. A small product needs enough logs to investigate failed logins, but not so much data that it leaks passwords or personal details. Start by deciding which questions your logs must answer. The guidance here draws on the OWASP Logging Cheat Sheet and the UK National Cyber Security Centre (NCSC) guidance.

Start with the questions

The NCSC’s introduction to logging for security purposes advises you to start by listing the logs that could show whether an incident has happened, and what each log can answer. It recommends starting with the default settings, then removing only the information that is least likely to answer those questions. Its table of priority categories is not an exhaustive list, so check your own system for other sources.

A useful way to test each log is to write down the question it must answer, such as who changed a setting or when an account was locked. If the event you record cannot answer that question, either add the missing detail or drop the event. Logging everything at high volume makes the important events harder to find.

Log the events that OWASP lists

The OWASP Logging Cheat Sheet lists the events to log where possible:

  • authentication successes and failures;
  • authorisation (access control) failures;
  • input validation failures, such as invalid parameter names and values;
  • session management failures;
  • use of administrative privileges, including all actions by application administrators;
  • deserialisation failures.

The NCSC also advises recording the source and destination address or host name, which identify the machine, and the account name, which identifies the user.

Keep passwords, tokens and keys out of logs

The OWASP sheet says that these items should usually not be recorded directly in logs: authentication passwords, session identifiers (a hashed value may be used if you need to track a session), access tokens, encryption keys and other primary secrets, and sensitive personal data or some forms of personally identifiable information. Check where forms, error messages and debug output could copy these values into a log. For where secrets should live instead, see Keeping secrets out of your code and logs.

Working on something similar in your own product? A few honest sentences are enough – we read every enquiry and reply by email. Apply with your idea

Protect the logs and their time

OWASP says that logging mechanisms and collected event data must be protected from misuse. It recommends tamper detection, copying log data to read-only media as soon as possible, recording and monitoring all access to the logs, and restricting and periodically reviewing who may read them. If log data crosses untrusted networks, use a secure transmission protocol.

The NCSC adds that logs should be protected against tampering and unauthorised access, that write permissions should be limited, and that transport encryption should be used where possible. It advises logging with UTC timestamps, from sources synchronised to an accurate time source.

Keep logs for at least six months

The NCSC recommends holding logs that let you answer incident questions for at least six months, and longer if your budget allows. Decide the period once, write it down, and apply it to every log source.

TopicGuidance
RetentionAt least six months for logs that answer incident questions (NCSC)
TimeUTC timestamps, synchronised to an accurate time source (NCSC)
AccessRead rights restricted and reviewed, and all access recorded (OWASP)

A practical checklist

  1. List the OWASP events that your product produces, and log them with the source address and account name.
  2. Search the code for values that must never be logged, and remove them.
  3. Set all servers to one accurate time source, and write logs in UTC.
  4. Restrict who can read the logs, and record who reads them.
  5. Keep logs for at least six months, and check periodically that logging still runs.

Logs also feed alerts, described in monitoring and alerts for a small product. For how stored passwords are protected, see Storing passwords correctly in PHP.

Common questions

Which events should a small product log?
The OWASP Logging Cheat Sheet lists authentication successes and failures, authorisation failures, input validation failures, session management failures and all actions by administrators. The NCSC also advises recording the source and destination address and the account name.
What must never be written to a log?
OWASP says that authentication passwords, access tokens, encryption keys and other primary secrets should usually not be recorded. Session identifiers may be replaced with a hashed value, and sensitive personal data should stay out of logs too.
How long should logs be kept?
The NCSC recommends holding logs that let you answer incident questions for a minimum of six months, and longer if your budget allows.

Sources

  1. Logging Cheat Sheet, OWASP. Accessed 24 November 2026
  2. Introduction to logging for security purposes, National Cyber Security Centre (NCSC). Accessed 24 November 2026

Further reading

Have an idea that should exist? Or a working product that needs more customers, a new website or a complete rework? Bring us anything. Apply with your idea

All notes