Application Logging

Architecture

Centralize logs from multiple application components:

  • Web servers sending access and error logs
  • Application containers with structured JSON logs
  • Background workers processing queued tasks
  • Scheduled jobs with execution traces

When to Use

This pattern is ideal when you need:

  • Single pane of glass for all application logs
  • Cross-service correlation for distributed tracing
  • Real-time error alerting and dashboards
  • Historical log analysis for debugging

Configuration

module "app_logs" {
  source  = "registry.patterneddesigns.ca/essentials/cloudwatch-logs/aws"
  version = "1.3.0"

  log_group_name    = "/app/${var.environment}/${var.service_name}"
  retention_in_days = var.environment == "production" ? 90 : 14

  metric_filters = [
    {
      name             = "errors"
      pattern          = "{ $.level = \"ERROR\" }"
      metric_name      = "ErrorCount"
      metric_namespace = "${var.service_name}/Logs"
    }
  ]
}

Considerations

  • Use structured JSON logging for better querying
  • Set appropriate retention based on environment
  • Create metric filters for key error patterns
  • Consider log volume and associated costs