In brief
An application should log the events that answer "who did what, when, from where and with what result": successful and failed sign-ins, access denials, permission and password changes, data exports, admin actions and input validation failures. It must not log passwords, tokens, session IDs, keys, card data or unnecessary personal data. Entries follow a fixed format, go to a separate system the application cannot alter, and important events trigger an alert.
A security log is not a debug log
Most applications log a lot, but not what the security team needs. A debug log says why something does not work. A security log says who did what and whether they were allowed to.
| Debug log | Security event log | |
|---|---|---|
| Question | why the order was not saved | who exported the customer list at night |
| Audience | developers, the operations team | SOC analysts, auditors, incident investigators |
| Format | often free text, variable | fixed, structured, with an event name |
| Retention | days, weeks | per company policy and regulation, usually longer |
| Protection | normal team access | a separate system, restricted reading, protection against changes |
The 2025 edition of the OWASP Top 10 kept "Security Logging and Alerting Failures" in ninth place. The change of name from "monitoring" to "alerting" is deliberate: a log that nobody reads and that triggers nothing does little to detect an incident.
What to log
The OWASP Logging Cheat Sheet lists events an application should always log, and the OWASP Logging Vocabulary proposes common names for them. Common names make it easier to write detection rules for many applications at once.
| Event | Example name | Why |
|---|---|---|
| successful and failed sign-in | `authn_login_success`, `authn_login_fail` | detecting password guessing and account takeover |
| account lockout after many attempts | `authn_login_lock` | a signal of an attack on a specific account |
| password or MFA change, token creation and revocation | `authn_password_change`, `authn_token_revoked` | account takeover often starts with changing sign-in details |
| access denied to a resource | `authz_fail` | attempts to read other users' data by changing an ID |
| permission and role changes | `privilege_permissions_changed` | granting oneself an admin role |
| reading and exporting sensitive data | `sensitive_read` | a leak through a privileged account |
| creating, changing, deleting a user | `user_created`, `user_deleted` | ghost accounts after an employee leaves |
| rate limit exceeded | `excess_rate_limit_exceeded` | automated attacks on the API |
| input validation failure | `input_validation_fail` | scanning and injection attempts |
| a skipped workflow step | `sequence_fail` | bypassing approval of a transfer or an order |
| monitoring disabled, application restart | `sys_monitor_disabled`, `sys_restart` | covering tracks |
Add your system's own business events to this list: a change to a partner's bank account in the ERP, a change to a credit limit, manual approval of an invoice without a goods receipt. These are what attackers target, and a generic framework does not know about them.
What a good entry looks like
An entry has a fixed format, ideally JSON, and answers: when, where, who, what and with what result. An example of a failed attempt to read someone else's invoice:
{
"datetime": "2026-11-30T09:14:02.118Z",
"appid": "portal-klienta",
"version": "4.12.0",
"event": "authz_fail:faktura_read",
"level": "WARN",
"user_id": "u-48213",
"tenant_id": "firma-1907",
"resource": "faktura/772415",
"source_ip": "203.0.113.24",
"request_method": "GET",
"request_uri": "/api/faktury/772415",
"result": "denied",
"trace_id": "4bf92f3577b34da6a3ce929d0e0e4736"
}A few rules decide whether an entry is useful:
- Time in UTC with milliseconds, and servers with synchronized clocks. Without this you cannot line up events from several systems.
- A user ID, not an email address. It lets you link events while limiting personal data in the log.
- A trace ID (`trace_id`) that links the entry to logs and traces from other services. OpenTelemetry, described in OpenTelemetry, provides a common standard for this.
- The result of the operation, because "attempt" and "success" are different alerts.
What not to log
A log is a copy of data read by more people and systems than the production database. According to OWASP, exclude or mask:
- passwords, including mistyped ones (often an almost correct password),
- access tokens, API keys, database connection strings and encryption keys,
- session IDs; if you need to track them, log a hash,
- full card numbers and bank account numbers,
- personal data beyond what is needed, including national ID numbers, document numbers and health data,
- full request and response bodies that may contain such data.
This is not only a security requirement. The GDPR requires data minimization (Article 5(1)(c)), and a user ID and an IP address make it possible to link an entry to a person. Logs containing them need retention and access rules like any other personal data.
A separate problem is log injection. When an application writes user-supplied text containing line breaks to a log, an attacker can add a forged entry. A structured format (JSON) and encoding of input close this route.
Where logs go and how to protect them
A log an attacker can delete will not help during an incident. A practical setup:
- Ship logs continuously to a central system, such as a SIEM or a log platform, instead of keeping files on the application server.
- Write-once storage: append-only, with a separate account and separate permissions from the application.
- Restricted read access that is itself logged.
- Retention per policy: shorter in fast storage for detection, longer in an archive for incident analysis. NIST SP 800-92 recommends that retention periods follow policy and legal requirements.
- Alerts on important events: a burst of `authn_login_fail` from one address, `privilege_permissions_changed` outside a change ticket, a night-time `sensitive_read` on thousands of records.
How a SOC turns such events into detection rules is described in SOC and SIEM, and an online banking example in the case study on detection rules and playbooks. B2Bnetwork engineers build platforms that collect logs, metrics and traces in one place, with retention and access defined as code, as part of Platform and DevOps.
Questions and answers
How do you check that an application really logs security events?
With tests, like any other feature. An automated test performs a failed sign-in or an attempt to read another user's record and checks that an entry with the right event name and fields was created. From time to time, also run an attack scenario in a test environment and check that an alert appeared in the SIEM.
How long should security event logs be kept?
As long as company policy, sector regulations and contracts require. A few weeks in fast storage is enough for detection, but incidents are sometimes discovered months later, so the archive should reach further back. Remember that logs with user IDs are personal data, so retention needs a justification.
Should every data read be logged?
Not every one, because the volume quickly outweighs the benefit. Log reads of sensitive data (medical records, customer data for export, searches across the whole database) and bulk operations. Users viewing their own data usually does not need a separate security event.
Can the security log live in the same system as application logs?
It can, if security events are tagged, follow a fixed format and have separate access and retention rules. What matters is that the application and its administrators cannot change or delete them. In larger companies, security events also go to a SIEM, where detection rules run.