# Wonder Logger Configuration Example
#
# This file demonstrates all available configuration options for Wonder Logger.
# Save this as 'wonder-logger.yaml' in your project root.
#
# Environment variables can be used with the syntax:
#   ${VAR_NAME}          - Required variable (throws if not set)
#   ${VAR_NAME:-default} - Optional variable with default value

# =============================================================================
# Service Metadata
# =============================================================================
service:
  # Service name (required)
  name: ${SERVICE_NAME:-my-api}

  # Service version
  version: ${SERVICE_VERSION:-1.0.0}

  # Deployment environment
  environment: ${NODE_ENV:-development}

# =============================================================================
# Logger Configuration
# =============================================================================
logger:
  # Enable/disable logger
  enabled: true

  # Minimum log level: trace, debug, info, warn, error, fatal, silent
  level: ${LOG_LEVEL:-info}

  # Values never to print. A key (no '.', '[' or '*') is redacted at any depth and in any
  # case, including inside Errors and child() bindings; a path (req.headers.authorization) is
  # redacted exactly where it points. The message string is never redacted.
  redact:
    - password
    - token
    - apiKey
    - secret
    # Replace with a short digest instead, so lines about one user stay joinable:
    # - paths: [userId]
    #   hash: { algorithm: sha512, length: 16 }

  # Transports define where logs are sent
  transports:
    # Console transport - aligned variant (recommended for development)
    # Variants: json, pretty, minimal, aligned
    - type: console
      variant: aligned
      level: debug
      alignedOptions:
        colorize: true          # Set false to disable colors, or use NO_COLOR env var
        showTimestamp: true
        timestampFormat: iso    # 'iso' or 'epoch'
        dataFormat: json        # 'json', 'inline', or 'hidden'

    # Console transport - json variant (recommended for production)
    # - type: console
    #   variant: json
    #   level: info

    # Console transport - pretty variant (pino-pretty multi-line)
    # - type: console
    #   variant: pretty
    #   level: debug
    #   prettyOptions:
    #     colorize: true
    #     translateTime: "yyyy-mm-dd HH:MM:ss"
    #     ignore: "pid,hostname"

    # Console transport - minimal variant (message only, no data)
    # - type: console
    #   variant: minimal
    #   level: info
    #   minimalOptions:
    #     colorize: true

    # File transport (write to disk)
    - type: file
      dir: ./logs
      fileName: app.log
      level: info
      mkdir: true # Create directory if it doesn't exist
      sync: false # Use async I/O for better performance

    # Memory transport (store logs in memory for querying/testing)
    - type: memory
      name: ${SERVICE_NAME:-my-api} # Registry name for querying (defaults to service name)
      maxSize: 10000 # Maximum logs to store (circular buffer)
      level: debug # Log level for this transport
    # Query logs programmatically:
    # import { getMemoryLogs, getMemoryLogStream } from '@recoverysky/wonder-logger'
    # const logs = getMemoryLogs('my-api', { since: Date.now() - 60000 })
    # const logs$ = getMemoryLogStream('my-api')

    # OpenTelemetry transport (send to OTEL Collector/Loki)
    - type: otel
      endpoint: ${OTEL_LOGS_ENDPOINT:-http://localhost:4318/v1/logs}
      level: info
      exportIntervalMillis: 5000

  # Plugins extend logger functionality
  plugins:
    # Inject OpenTelemetry trace context (trace_id, span_id) into logs
    traceContext: true

    # Provide Morgan-compatible stream for HTTP request logging
    morganStream: false

# =============================================================================
# OpenTelemetry Configuration
# =============================================================================
otel:
  # Enable/disable OpenTelemetry
  enabled: true

  # Distributed Tracing Configuration
  tracing:
    enabled: true

    # Exporter type: console, otlp, jaeger, none
    # Use 'none' to create spans for trace context without console output
    exporter: ${OTEL_TRACE_EXPORTER:-otlp}

    # The otlp exporter reads OTEL_EXPORTER_OTLP_ENDPOINT from the environment
    # (base URL, e.g. http://collector:4318 — /v1/traces is appended). There
    # is no endpoint key here.

    # Fraction of traces started here to sample (0.0 to 1.0). A caller's
    # sampled traceparent is always honoured regardless of this value.
    sampleRate: 1.0

    # Request paths never traced, together with every span under them.
    # An entry matches exactly and as a subtree (/status covers /status/ready).
    # Applied before the parent decision, so a sampled traceparent from a
    # poller does not bring a health probe back.
    ignorePaths:
      - /ping
      - /status

  # Metrics Configuration
  metrics:
    enabled: true

    # Metrics exporters (can have multiple)
    exporters:
      # Prometheus pull exporter (scrape endpoint)
      - type: prometheus
        port: ${PROMETHEUS_PORT:-9464}

      # OTLP push exporter (remote write)
      - type: otlp
        # Optional full URL (/v1/metrics included). Leave it out and the exporter
        # reads OTEL_EXPORTER_OTLP_METRICS_ENDPOINT, then OTEL_EXPORTER_OTLP_ENDPOINT
        # (+ /v1/metrics), then localhost:4318. A ${VAR:-default} here overrides both.
        # endpoint: http://collector:4318/v1/metrics
        exportIntervalMillis: 60000 # Export every 60 seconds

    # Global export interval (overridden by individual exporter settings)
    exportIntervalMillis: 60000

  # Auto-instrumentation Configuration
  instrumentation:
    # Enable automatic instrumentation for common libraries
    auto: true

    # Include HTTP request/response attribute hooks
    http: true
