A security log should help your team reconstruct what happened, when it happened, and how the application responded. Every field you record also becomes data your team must protect. Start with the questions you expect to investigate and give each event only the fields needed to answer them.
- Application
Creates an approved event with a correlation ID
- Collector
Receives the set of fields configured for that source
- Log store
Keeps the event available to the assigned response role
- Alert and export
May retain copies under separate access and expiry rules
Pick events your team can act on
Start with sign-in outcomes, authorization denials, changes to roles and account recovery settings, and administrative actions such as bulk exports. Choose events that matter for your application. For each one, write down who will review it and what they might do with it. For example, an on-call engineer might review an unusual burst of sign-in failures, while an account owner might need to confirm who approved a new administrator.
Define a small set of fields across these events. Start with the event time, service, environment, event name, outcome, and an application-generated correlation identifier that connects related records. Distinguish event time from receipt time when logs can arrive late. Use a fixed reason code where an outcome needs explanation. Include an internal actor or resource identifier when the investigation needs it and the destination is approved for it. Protect identifiers that can be linked to people or confidential records.
Decide which fields may leave the application
Define an allowlist of fields for each event type. Add only approved values to the structured event before it leaves the application. Exclude passwords, one-time codes, recovery links, API keys, access tokens, authorization headers, cookies, raw session identifiers, and full request or response bodies from routine logs. For web requests, prefer an approved route name or template because a full URL can contain identifying values in the path or query string.
For example, a failed administrative export can record export_denied, permission_missing, the service, and a request ID. Add a permitted internal actor identifier if the investigator needs it. The event can explain the denial without copying export filters or customer records. Use fixed event names and reason codes, and validate and safely encode any permitted values that come from outside the application.
Map each tool that receives diagnostics. A reverse proxy, error tracker, or tracing agent can collect data independently of the application logger. Review each integration's default capture settings and drop disallowed fields at the earliest layer you control. Inspect alert notifications, export files, and restricted copies as separate destinations with their own access and retention rules.
Protect records once collected
Give log access to the people and services that need it, with separate permissions for reading, writing, and administration where possible. Protect transport, restrict changes and deletion, and review who can view or export records. Agree on retention for each destination based on investigation needs, data sensitivity, and applicable obligations. Account for copies in backups, alerts, and exported files when deciding how records will be removed.
- Decision context
Time, service, outcome, and an approved reason code
- Linking context
Application-generated request ID and a permitted internal actor ID when needed
- Fields to exclude
Export contents, customer filters, raw cookies, and access tokens
Verify what actually arrives
In an approved test environment, use distinctive synthetic markers for fields you intend to exclude. Generate representative sign-in, denial, and error events. Inspect the application output, stored events, forwarded alerts, and any exports for each marker. Then use the intended responder role to trace one event across services by its approved identifier. Simulate an unavailable logging destination in the same environment and verify the expected application behavior and the signal for missed events.
Repeat those checks when adding diagnostics, changing infrastructure, or enabling verbose logging. An event definition in code documents what the application meant to send. The stored record shows what the system actually collected.
Review common web application security risks ยท Learn how to read a security assessment report