beginner By Mathias Paulenko

Logging Standards Document

A document template for defining structured logging conventions, log levels, retention, and observability requirements across services.

Note: This guide follows English-language naming conventions and terminology standards common in international development teams. Examples use English identifiers and comments to maximize compatibility across codebases and tooling.

Overview

A Logging Standards Document defines how services, applications, and infrastructure produce logs. Consistent logging makes debugging, monitoring, security investigation, and compliance easier. This template covers log levels, structured formats, required fields, retention, sampling, and security rules.

When to Use

  • For alternatives, see Complete Guide to Observability with the Grafana Stack.

  • Onboarding a new service or development team.

  • Consolidating logs from multiple systems into a central observability platform.

  • Preparing for a security audit or compliance review.

  • Investigating a production incident where logs are incomplete or inconsistent.

  • Defining a logging strategy for microservices or serverless environments.

Prerequisites

  • A log aggregation platform such as ELK, Splunk, Datadog, Grafana Loki, or CloudWatch.
  • A shared timestamp standard and timezone policy.
  • A list of critical events that must always be logged.
  • Agreement on sensitive data classification and log redaction rules.

Solution

Document

1. Log Levels

LevelUseExample
DEBUGDetailed diagnostic information during developmentcache miss for key user:1234
INFONormal application eventsuser logged in, order completed
WARNUnexpected but recoverable situationsconnection timeout, retrying
ERRORFailures that affect operationpayment gateway returned 500
FATALCritical failures requiring immediate attentiondatabase unavailable, service shutdown

Guidelines:

  • DEBUG must be off in production by default.
  • INFO is the default production level for most services.
  • ERROR must trigger an alert or ticket.
  • FATAL must page the on-call team.

2. Structured Log Format

All logs must be emitted as JSON with the following required fields:

FieldTypeDescriptionExample
timestampISO 8601Event time in UTC2026-06-27T14:30:00Z
levelstringLog levelINFO
servicestringService or application namepayment-service
environmentstringEnvironmentproduction
messagestringHuman-readable summaryOrder 12345 completed
correlation_idstringRequest trace IDabc-123-def
span_idstringOpenTelemetry span IDspan-xyz-789

Optional fields:

  • user_id: Identity of the user associated with the event.
  • tenant_id: Identifier for multi-tenant isolation.
  • duration_ms: Time taken to complete an operation.
  • error_code: Stable error code for programmatic handling.
  • source_file: File and line where the log was emitted.

3. Required Event Categories

CategoryEvents to LogLevel
AuthenticationLogin, logout, failed login, MFA challengeINFO / WARN
AuthorizationAccess denied, permission escalationWARN
Data changesCreate, update, delete on sensitive recordsINFO
ErrorsExceptions, external failures, retriesERROR
PerformanceSlow queries, high latency, timeoutsWARN
SecuritySuspicious activity, rate limit hits, blocked requestsWARN
OperationalStartup, shutdown, configuration changesINFO
BusinessOrder placed, payment received, workflow completedINFO

4. Sensitive Data and Redaction

Data TypeLoggedRedaction
PasswordsNeverRedact or exclude
Credit card numbersNeverTokenize or exclude
API keysNeverRedact or exclude
Personal namesWith approvalMask if not required
Email addressesAllowedPartial mask for non-admins
IP addressesAllowedAllowed for security logs
User IDsAllowedAllowed

Rules:

  • Never log secrets or credentials.
  • Use allowlists for personal data fields.
  • Redact or tokenize values before logging.
  • Encrypt logs if they contain sensitive data.

5. Retention and Sampling

Log TypeRetentionSamplingNotes
Application logs30 days100%Keep all for debugging
Security logs1 year100%Compliance requirement
Audit logs7 years100%Legal and regulatory
Debug logs7 days100%Only when enabled
High-volume trace logs14 days1% or liveCost control

6. Log Aggregation and Transport

RequirementRule
TransportSend logs to the central platform with backpressure handling.
OrderingUse timestamps for ordering; tolerate minor clock skew.
BufferingBuffer locally if the collector is unavailable.
EncodingUse UTF-8 JSON.
BackupsReplicate critical logs to a secondary storage.
AlertingRoute ERROR and FATAL logs to the alerting system.

Explanation

Consistent logging transforms noisy text files into searchable, structured data. By defining levels, fields, and retention, teams can correlate events across services, investigate incidents faster, and meet compliance requirements. Structured logs also integrate with tracing and metrics to create a complete observability picture.

Structured Log Format Example

{
  "timestamp": "2026-07-11T10:55:32.123Z",
  "level": "ERROR",
  "service": "auth-service",
  "environment": "production",
  "correlationId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
  "userId": "usr_8f7e6d5c",
  "message": "JWT validation failed",
  "errorCode": "AUTH_JWT_INVALID",
  "context": {
    "endpoint": "/api/v1/auth/verify",
    "method": "POST",
    "statusCode": 401,
    "durationMs": 12,
    "ipAddress": "10.0.1.42",
    "userAgent": "MobileApp/2.3.1"
  },
  "error": {
    "type": "TokenExpiredError",
    "message": "jwt expired",
    "stack": "TokenExpiredError: jwt expired\n    at ..."
  }
}

Log Level Decision Matrix

=== When to Use Each Log Level ===

FATAL   - System cannot continue. Process will exit.
          Examples: config load failure, port binding error, OOM

ERROR   - Operation failed but system continues.
          Examples: request failed, DB query error, external API timeout

WARN    - Unexpected but recoverable condition.
          Examples: retry succeeded, cache miss, deprecated API usage

INFO    - Significant business or operational event.
          Examples: user login, order placed, deployment started

DEBUG   - Diagnostic detail for troubleshooting.
          Examples: variable state, query params, cache contents

TRACE   - Finest-grained execution flow.
          Examples: function entry/exit, loop iteration count

RULES:
  - Production: INFO and above (DEBUG/TRACE off)
  - Staging: DEBUG and above
  - Development: TRACE and above
  - Never log at DEBUG in production unless actively debugging
  - ERROR must be actionable — if it is not, it is INFO

Variants

  • Cloud logging standards: Tailored for AWS CloudWatch, Azure Monitor, or Google Cloud Logging.
  • Container and Kubernetes logging: Covers sidecar log shippers, Fluentd, and pod log conventions.
  • Security-focused logging: Emphasizes audit events, integrity, and tamper detection.
  • Serverless logging: Addresses short-lived functions, cold starts, and centralized log collection.
  • Mobile or client logging: Focuses on privacy, batching, and offline buffering.

What works

  • Use a single structured format across all services.
  • Include a correlation ID in every request to enable distributed tracing.
  • Log outcomes at business boundaries, not every internal step.
  • Keep log messages concise and add context as structured fields.
  • Avoid logging sensitive data by default.
  • Use log levels consistently so alerts are meaningful.
  • Review retention policies against cost and compliance needs.
  • Test log parsing and alerting rules as part of deployments.

Common Mistakes

  • Logging everything at INFO, making it hard to spot real issues.
  • Writing logs as plain text that cannot be parsed automatically.
  • Omitting timestamps or using inconsistent formats.
  • Including passwords or tokens in logs.
  • Not including enough context to reproduce a failure.
  • Keeping logs forever and increasing storage costs unnecessarily.
  • Not correlating logs across services during an incident.

Troubleshooting

  • No logs for a failing request: verify log shipping, retention, and that the request reached the service.
  • Alert fires but the service is healthy: tune thresholds and use multi-signal alerts.
  • Dashboard shows stale data: check refresh intervals, query range, and data source lag. Verify that the metric still exists.
  • High cardinality metrics explode costs: drop high-cardinality labels, aggregate before ingest, or use sampling.
  • Trace is incomplete across services: ensure all services propagate trace context. Instrument async and background jobs.

Further Reading

  • Official documentation: check the current reference for the framework or tool used.
  • Related guides: explore the logging and observability guides for deeper coverage.
  • Complementary patterns: review design patterns applicable to your technology stack.
  • Public postmortems: study real incidents from teams that faced similar production issues.

Production Notes

  • Deploy gradually using canary or blue-green to catch regressions early.
  • Configure alerts for error rate, p99 latency, and failure rate before enabling in production.
  • Document the rollback in the runbook; test the procedure in staging at least once per quarter.
  • Review structured logs with correlation IDs to trace requests end-to-end during incidents.

Key Takeaways

  • Apply logging standards document when you need a practical solution for your use case.
  • Monitor performance after implementation; measure latency, errors, and resource usage before and after.
  • Check the Troubleshooting section for common failures; most have documented root causes with fixes.
  • Keep dependencies updated and run tests in CI to prevent production regressions.

Common Production Pitfalls

  • Leaving required fields blank or using vague one-word answers.
  • Filling the document once and never updating it after scope or decisions change.
  • Storing the document where the team does not look during incidents or reviews.
  • Not assigning an owner, due date, or review cadence.
  • Copying boilerplate without removing sections that do not apply.
  • Skipping version control, which makes rollback and accountability impossible.
  • Failing to link the document to related decisions or follow-up actions.
  • Avoiding quarterly reviews that would retire stale or unused sections.

Frequently Asked Questions

Should we log in production at DEBUG level?
No, DEBUG should be off by default. Enable it temporarily for targeted troubleshooting, and disable it when the issue is resolved.
What is a correlation ID?
A correlation ID is a unique identifier passed through all services that handle a single request. It allows you to group related log entries across a distributed system.
How do we handle sensitive data in logs?
Use an allowlist approach: only log fields that are explicitly approved, and redact or tokenize sensitive values before they reach the log stream.
How do we implement correlation IDs in a microservices architecture?
Generate a correlation ID at the API gateway for each incoming request. Propagate it via HTTP headers (e.g., X-Correlation-Id). Each downstream service reads the header, includes it in all log...
What is log sampling and when should we use it?
Log sampling means logging only a percentage of events to reduce volume and cost. Use sampling for high-volume, low-value logs (e.g., health check responses, static asset requests). Never sample...
How do we handle log storage costs?
Control costs through: tiered retention (hot storage for 7-30 days, cold archive for longer), sampling high-volume logs, compressing log files, excluding noisy endpoints from logging, and using...
What is the difference between logs, metrics, and traces?
Logs are discrete events with timestamps — what happened at a specific moment. Metrics are aggregated measurements over time — CPU usage, request count, error rate. Traces follow a single request...
How do we test logging in CI/CD?
Add tests that verify: log format is valid JSON, required fields are present (timestamp, level, service, correlationId), sensitive data is not logged, log levels are used correctly, and log volume...