Skip to main content

Structured Logging Policy

1. Objective​

This policy defines the requirements for the production, formatting, centralisation, retention and protection of logs in the organisation's applications and systems.

Logs are the primary record of a system's behaviour - they are the basis of all incident investigation, compliance audit and detection of security anomalies. Decentralised, non-normalised logs, or logs without integrity guarantees, do not fulfil this role: they are noise, not evidence. The transition from ad-hoc logging to centralised structured logging is a paradigm shift - not a change of tool.

The objective of this policy is to ensure that:

  • All systems produce logs in a structured and normalised format
  • Mandatory security events are always recorded, regardless of level
  • Sensitive data and PII never appear in logs without adequate masking
  • Logs are centralised, immutable at L3, and retained for the defined periods
  • Log correlation across systems is possible via trace ID and common fields

2. Scope and applicability​

This policy applies to all running systems that produce events relevant to security, operations or audit. It includes web applications, APIs, workers, jobs, CI/CD pipelines, infrastructure and authentication systems.

LevelApplicability
L1Mandatory; structured format; security events from section 4; logs persisted outside the instance; minimum retention; centralisation recommended
L2Mandatory; structured JSON format; mandatory security events; centralisation; minimum retention
L3Mandatory; JSON/ECS; complete events; centralisation + SIEM; WORM; regulatory retention

3. Logging format​

3.1 Mandatory format​

At L2/L3, all logs must be produced in JSON format (or compatible with Elastic Common Schema - ECS), machine-readable and processable without custom parsing:

  • No unstructured free-text logs in critical components
  • No multiple log formats in the same system without normalisation at ingestion

3.2 Minimum event schema​

Each log event must contain, at a minimum, the following fields:

FieldExampleMandatory
timestamp2025-07-21T10:35:14.321ZYes; ISO 8601 UTC
levelINFO, WARN, ERROR, DEBUGYes; standardised levels
event.actionuser.login, file.upload, api.callYes at L2/L3; consistent taxonomy
applicationapi-gateway, worker-paymentYes; logical component
environmentproduction, stagingYes
trace.idxyz-9876-abcdYes at L2/L3; correlation across systems
user.idusr-1234 (internal, never email or name)When applicable
src.ip192.168.1.20In authentication and access events
http.status_code200, 401, 500In APIs and endpoints
messageHuman-readable description of the eventYes

4. Mandatory security events​

The following security events must always be recorded, regardless of the application's criticality level:

EventMinimum mandatory fields
Successful authenticationuser.id, src.ip, timestamp, method (password/MFA/SSO)
Failed authenticationuser.id (or attempt), src.ip, timestamp, motivo
Logout / session expiryuser.id, session.id, timestamp
Access denied (403)user.id, resource, action, src.ip, timestamp
Change to sensitive datauser.id, resource, acção, valor anterior (hash), timestamp
Change to permissions/rolesactor.id, target.id, permissĂŁo alterada, timestamp
Administrative operationactor.id, acção, target, timestamp
Relevant internal errorerror.type, error.message, stack trace resumido, trace.id
File upload/downloaduser.id, filename, size, method, timestamp
Call to an external APIendpoint, method, status, duration, trace.id

5. Absolute prohibitions in logs​

The following data must never appear in logs, regardless of level:

Prohibited dataAlternative
Passwords, PINs, answers to secret questionsNever record - not even as a hash
Session tokens, full JWTs, API keysRecord only the prefix (e.g. Bearer eyJ... → Bearer eyJ[redacted])
Credit card numbers, IBANMandatory masking: ****-****-****-1234
Health data, biometric dataNever record in operational logs
Directly identifiable PII (full name + address + tax ID number)Use internal user.id; masking of PII fields in debug logs
Secrets, private keys, certificatesNever
warning

Recording sensitive data in debug or error logs is one of the most common sources of PII exposure in production systems. DEBUG-level logs must be disabled in production or filtered before centralised ingestion.


6. Log centralisation​

RequirementL1L2L3
Logs centralised in a logging system (ELK, Loki, Splunk, etc.)RecommendedMandatoryMandatory
Ingestion pipeline with schema normalisationRecommendedMandatoryMandatory
Correlation possible by trace.id across servicesRecommendedMandatoryMandatory
SIEM integrationNot applicableRecommendedMandatory
CI/CD pipeline logs centralisedRecommendedMandatoryMandatory

7. Log retention​

Log typeL1L2L3
Operational logs (runtime, errors)30 days90 days1 year
Security logs (authentication, authorisation, changes)90 days1 year2 years
Audit logs (administrative operations, access to sensitive data)1 year1 year3 years
CI/CD pipeline logs30 days90 days1 year
Logs automatically generated by high-risk AI systems (OPS-011/012)At least 6 months1 year2 years
note

Precedence. The periods in this table are the minimum recommended by the Manual (the Manual's choice) and do not exhaust what is expected of the organisation. The most demanding of the following prevails:

  • (a) applicable EU law — for example, logs automatically generated by high-risk AI systems are kept «for a period appropriate to the intended purpose of the high-risk AI system, of at least six months» (AI Act, Articles 19(1) and 26(6)), and the technical documentation of products with digital elements, including the SBOM, is kept available «for at least 10 years after the product with digital elements has been placed on the market or for the support period, whichever is longer» (CRA, Article 13(13)). Under DORA, it is the financial entity that establishes the retention period, taking into account, among other factors, the results of the ICT risk assessment (Delegated Regulation (EU) 2024/1774, Article 12(2)); entities covered by Implementing Regulation (EU) 2024/2690 maintain logs «for a predefined period» (Annex, point 3.2.5);
  • (b) national legislation, including the transposition of NIS2 and sectoral regimes (for example, anti-money laundering, tax, employment, healthcare);
  • (c) supervisory guidance and expectations (for example EBA, ESMA, EIOPA, Banco de Portugal, CMVM, ASF, ANACOM, CNCS), which are not law but are expected in audits;
  • (d) normal sector expectations: standards and frameworks assumed by contract or expected by the market (for example PCI DSS for payment card data, ISO/IEC 27001 and SOC 2 in customer audits, customer and insurer requirements).

The Manual does not reproduce the periods of regimes (b) to (d): the organisation maps the applicable period in the version in force of each one. In any case, where logs contain personal data, they are kept for no longer than is necessary for the purpose (GDPR, Article 5(1), point (e)).

Organisation's retention map. The organisation maintains a map that shows, for each record type, the regime that sets the period — EU law, national legislation, supervisor, sector or this Manual — and the value adopted, which is the most demanding of those applicable. It is the artefact an auditor asks for; it is reviewed whenever an applicable regime changes.


8. Integrity and immutability​

RequirementL1L2L3
Logs protected from modificationMandatoryMandatoryMandatory
WORM storage (Write Once, Read Many)Not applicableRecommendedMandatory
Periodic hashing or signing of logsNot applicableRecommendedMandatory
Access to logs restricted and auditedMandatory (restricted access); auditing of access recommendedMandatoryMandatory
Alerts upon any attempt at alteration or deletionNot applicableRecommendedMandatory

8.1 Immutability and deletion of personal data​

A record that cannot be altered cannot be deleted on request either. So that immutability does not prevent the deletion of personal data (PRI-003), this rule applies to immutable logs and backups:

  • personal data enter only as an internal pseudonymous identifier, never as a direct identifier (name, email, document number);
  • any identifying content that has to stay in the record is encrypted with a per-person key, kept outside the immutable storage;
  • a deletion request is met by destroying that person's key (crypto-shredding); what remains of the record no longer identifies the person and is kept until the end of the retention period, with restricted access;
  • when a backup is restored, the deletions requested after the backup date are re-applied;
  • the decision is logged, together with the originating request.

Whether destroying the key counts legally as deletion is a matter for the DPO; the Manual prescribes the technical mechanism (PRI-005).


9. Responsibilities​

RoleResponsibility
DeveloperImplement structured logging according to the schema; do not record sensitive data; use trace.id
DevOps / SREConfigure the centralisation pipeline; ensure retention and immutability; manage the logging system
AppSec EngineerDefine mandatory security events; audit logs for PII; configure SIEM integration
GRC / ComplianceVerify compliance with regulatory retention periods; audit access to logs; reports

10. Review and audit of this policy​

This policy must be reviewed annually or after any of the following events:

  • An incident in which insufficient or missing logs hindered the investigation
  • Exposure of PII or sensitive data in logs
  • A regulatory change imposing new retention requirements

11. Normative and technical references​

ReferenceRelevance
SbD-ToE Ch. 12 - Monitoring and OperationsUS-01 (structured logging), US-07 (log security and integrity)
Elastic Common Schema (ECS)Reference schema for normalised fields
OWASP Logging Cheat SheetGood practices for secure logging
GDPR / RGPD - Art. 5(1)(e)Storage limitation of personal data
DORA (Art. 9) — Delegated Regulation (EU) 2024/1774, Art. 12 (simplified framework: Art. 34, point (f))Logging requirements for financial entities
NIST SP 800-92Guide to Computer Security Log Management
ISO/IEC 27001 - A.12.4Logging and monitoring