server:
  http_listen_port: 9080
  grpc_listen_port: 0

positions:
  filename: /tmp/positions.yaml

clients:
  - url: http://loki:3100/loki/api/v1/push

scrape_configs:
  - job_name: coordinator
    static_configs:
      - targets:
          - localhost
        labels:
          app: coordinator
          format: txt
          __path__: /var/log/coordinator/*log
    pipeline_stages:
      - logfmt:
          mapping:
            time:
            level:
      - labels:
          level:
      - timestamp:
          source: time
          format: RFC3339

##########################
## Custom JSON format
##########################
  - job_name: coordinator-json
    static_configs:
      - targets:
          - localhost
        labels:
          app: coordinator
          format: json-custom
          __path__: /var/log/coordinator-json-custom/*log

    pipeline_stages:
      - json:
          expressions:
            level: level  # Extracts the "level" field from the JSON log
            message: message  # Extracts the "message" field from the JSON log
            time: time  # Extracts the "time" field from the JSON log
            thread: thread  # Extracts the "thread" field from the JSON log
            logger: logger  # Extracts the "logger" field from the JSON log
            stackTrace: stackTrace # Extracts the "stackTrace" field from the JSON log
      - labels:
          level:  # Maps the extracted "level" to a label
      - structured_metadata:
          thread:
          logger:
      - timestamp:
          source: time
          format: RFC3339

  - job_name: coordinator-json-message-only
    static_configs:
      - targets:
          - localhost
        labels:
          app: coordinator
          format: json-custom-message-only
          __path__: /var/log/coordinator-json-custom/*log

    pipeline_stages:
      - json: # This stage parses the log line as JSON
          expressions:
            level: level  # Extracts the "level" field from the JSON log
            message: message  # Extracts the "message" field from the JSON log
            time: time  # Extracts the "time" field from the JSON log
            thread: thread  # Extracts the "thread" field from the JSON log
            logger: logger  # Extracts the "logger" field from the JSON log
            stackTrace: stackTrace # Extracts the "stackTrace" field from the JSON log
      - labels:
          level:  # Maps the extracted "level" to a label
      - template:
          source: output_msg
          template: '{{ .message }} logger={{.logger }} thread={{.thread}} {{ .stackTrace }}'
#          template: '{{ .message }} {{.logger }} {{.thread}} {{ Replace .stackTrace "\n\t" "\\n\\t" }}'
      - structured_metadata:
          thread:
          logger:
          stackTrace:
      - output:
          source: output_msg  # Sets the output log line to the value of the "msg" field
      - timestamp:
          source: time
          format: RFC3339
