Contact Us 1-800-596-4880

Viewing and Managing Log Output

Anypoint Flex Gateway enables you to push metrics to Fluentbit 1.7.9 logging services. Supported outputs can be found in Fluentbit’s Outputs reference. Refer to the Declarative Configuration Reference Guide for information on how to configure Flex Gateway for any of these supported outputs.

The following examples describe how to configure Flex Gateway for use with the File and HTTP outputs.

To enable access logging, you must:

  1. Configure the File or HTTP output.

  2. Apply the Message Logging policy via policy binding. See Access Logs.

File Configuration Example

Configure Flex Gateway to send formatted runtime and access logs to a file called log.txt (Fluentbit File output), located within /var/log directory. As an example, the following definition specifies a spec.logging.outputs.type value of file:

For Docker, in spec.logging.output.parameters.file, replace /var/log with the absolute path to the mounted configuration directory.
apiVersion: gateway.mulesoft.com/v1alpha1
kind: Configuration
metadata:
  name: logging-config
spec:
  logging:
    outputs:
    - name: default
      type: file
      parameters:
        file: /var/log/log.txt # Docker: replace `/var/log` with the absolute path to the mounted configuration directory
        format: template
        template: |
          [{logger}][{level}][{kind}] {message}
    runtimeLogs:
      logLevel: info
      outputs:
      - default
    accessLogs:
      outputs:
      - default

HTTP Configuration Example

In addition to configuring logging for Fluentbit File output, you can also configure for Fluentbit HTTP output. As an example, the following definition specifies a spec.logging.outputs.type value of http:

apiVersion: gateway.mulesoft.com/v1alpha1
kind: Configuration
metadata:
  name: logging-config
spec:
  logging:
    outputs:
    - name: default
      type: http
      parameters:
        host: collectors.au.sumologic.com
        port: "443"
        URI: /receiver/v1/http/[PrivateKey]
        format: json_lines
        json_date_key: timestamp
        json_date_format: iso8601
    runtimeLogs:
      logLevel: info
      outputs:
      - default
    accessLogs:
      outputs:
      - default

Access Logs

After specifying access log output (as described in the previous configuration examples), you must enable access logs via policy binding.

For inline configurations, enable access logs by adding message-logging-flex to the spec.policies section of ApiInstance. The following is an inline configuration example:

apiVersion: gateway.mulesoft.com/v1alpha1
kind: ApiInstance
metadata:
  name: jsonplaceholder-api
spec:
  address: http://0.0.0.0:8080
  services:
    jsonplaceholder:
      address: https://jsonplaceholder.typicode.com:443/
      routes:
        - rules:
            - path: /api(/users/.*)
  policies:
    - policyRef:
        name: message-logging-flex
      config:
        loggingConfiguration:
          - itemName: "Access Log Request"
            itemData:
              message: "#[attributes.version ++ ' ' ++ attributes.method ++ ' ' ++ attributes.requestUri]"
              level: "INFO"
              firstSection: true
          - itemName: "Access Log Response"
            itemData:
              message: "#[attributes.statusCode ++ ' ' ++ (attributes.headers['content-length'] default '')]"
              level: "INFO"
              secondSection: true

For resource-based configurations, enable access logs by adding message-logging-flex to the spec.policyRef section of PolicyBinding. The following is a resource-based configuration example:

apiVersion: gateway.mulesoft.com/v1alpha1
kind: PolicyBinding
metadata:
  name: ingress-http-access-logs
spec:
  targetRef:
    kind: ApiInstance
    name: ingress-http
  policyRef:
    kind: Extension
    name: message-logging-flex
  config:
    loggingConfiguration:
      - itemName: "Access Log Request"
        itemData:
          message: "#[attributes.version ++ ' ' ++ attributes.method ++ ' ' ++ attributes.requestUri]"
          level: "INFO"
          firstSection: true
      - itemName: "Access Log Response"
        itemData:
          message: "#[attributes.statusCode ++ ' ' ++ (attributes.headers['content-length'] default '')]"
          level: "INFO"
          secondSection: true

View Logs

After enabling access logs via policy binding, to view agent, envoy, and Fluentbit logs, run the following commands.

For Linux:

journalctl -u flex-gateway*

For Docker:

  • To view agent and envoy logs:

    docker logs -f <container-id>
  • To view Fluentbit logs:

    1. Access the Flex Gateway docker container:

      docker exec -it <container-id> /bin/bash
    2. View Fluentbit logs:

      cat /var/log/flex-gateway-fluent/current

For Kubernetes:

  • To view agent and envoy logs:

    kubectl logs -f <pod-name>
  • To view Fluentbit logs:

    1. Access the Flex Gateway container:

      kubectl exec -it <pod-name> –- /bin/bash
    2. View Fluentbit logs:

      cat /var/log/flex-gateway-fluent/current