Skip to main content

Structured and Centralised Logging

🌟 Objective​

Ensure that all applications record events in a structured, secure, traceable and auditable manner, enabling anomaly detection, correlation between systems and support for incident response.


🧬 What structured logging is​

Structured logging consists of the emission of events with normalised fields, in a machine-readable format (e.g. JSON), transported to a centralised system and with integrity and retention guarantees.

📌 The structure and consistency of logs are essential for detection, traceability and effective investigation.


🧱 Recommended event structure​

Adopt a convention such as the Elastic Common Schema (ECS) or an in-house JSON-based format with common minimum fields.

FieldExampleNotes
timestamp2025-07-21T10:35:14ZISO 8601 in UTC
levelINFO, ERROR, WARN, DEBUGStandardised levels
event.actionuser.login, file.upload, api.callConsistent taxonomy
user.idabcd-1234Internal user ID, if applicable
src.ip192.168.1.20Source IP
trace.idxyz-9876Support for distributed tracing
applicationfrontend-web, api-gateway, worker-jobLogical component of the application

📦 Log transport and centralisation​

  • Use forwarding agents (e.g. Filebeat, Fluentbit, Vector)
  • Ensure secure transport (TLS) and temporary persistence (buffers)
  • Prefer continuous streaming (e.g. TCP, gRPC) over batch or UDP
  • Separate logging from the main process (e.g. sidecar container, logging driver)

Typical destinations:​

CategoryExamples
SIEMsSplunk, Sentinel, QRadar
ObservabilityElastic Stack, Loki, Datadog
HybridOpenSearch, Graylog, Grafana Tempo

🔒 Log security and integrity​

ControlDescription
Protected retention (WORM)Prevents alteration of logs after writing
Restricted accessWriting only via the application; reading audited
Signature or hashIntegrity verification per batch or file
Function isolationLogging separated from the application (e.g. forwarder, sidecar, service)

⚠️ Local-only logs are acceptable only for L1 applications - with periodic collection and documented justification.


📌 Minimum mandatory events​

Event typeMust contain…
Failed authenticationIP, user, timestamp, reason
Sensitive changesWho, what, where, before and after
Internal exceptionsStack trace (summarised), module, request ID
Upload / downloadName, size, user, method
External API callEndpoint, status, response time

✅ Good practices​

  • Do not record sensitive data (e.g. passwords, tokens), even encrypted
  • Separate logs by functional context (e.g. app.log, auth.log, db.log)
  • Validate the presence and format of logs in automated tests
  • Include request.id and trace.id for traceability of distributed requests
  • Emit logs at every security state transition

🧩 Link with detection and response​

Structured logging serves as the basis for the detection mechanisms defined in other documents:

DocumentRelation to this topic
03-alertas-eventos-criticos.mdGeneration of alerts from events
06-correlacao-anomalias.mdCorrelation between events for detection
08-matriz-controles-por-risco.mdLogging requirements per level L1–L3

🔐 A well-structured and centralised logging system is a prior requirement for effective detection, incident response, and compliance with frameworks such as SSDF, SLSA, ISO 27001.