---
schema_version: "1"
id: a1cf1c05eeaa57de31624b2d93f4e10cbdc09b55a6756ee76626df95f3ae0a28
title: Configuring External Logs for Flex Gateway in Local Mode
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/gateway/1.12/flex-local-third-party-logs-config.md
canonical_url: https://docs.mulesoft.com/gateway/1.12/flex-local-third-party-logs-config
source_site: docs.mulesoft.com
content_type: documentation
content_hash: c567bb39d968ab97998fab7cf0a14ff9ebe284bb9ba1cf9157d60d02b33d6085
description: MuleSoft Documentation Site
release: "1.12"
latest: false
---
---
product: Omni Gateway
version: 1.12
---

# Configuring External Logs for Flex Gateway in Local Mode

> For the full documentation index, see: https://docs.mulesoft.com/llms.txt

Anypoint Flex Gateway enables you to deliver runtime and access logs to any supported Fluent Bit
v3.2.10 output type. You configure log output via a custom YAML file. Additionally, to view access
logs, you must also apply a Message Logging policy.

The following configuration file examples demonstrate how to direct Flex Gateway logs to output
types: `File`, `HTTP`, and `Splunk`. However, you can use any Fluent Bit v3.2.10 output type, such
as `Azure Log Analytics`, `Amazon S3`, `Kafka`, and more. For a complete list of Fluent Bit output
types, see the [Fluent Bit documentation](https://docs.fluentbit.io/manual) for your Fluent Bit
version.

As well as being able to configure additional Fluent Bit log output types, Flex Gateway maintains
standard output logs. Use the standard output logs for quick checks when additional log output is
not needed. To view the standard output logs, see [View Logs](https://docs.mulesoft.com/gateway/latest/local-view-logs). Both
runtime and access logs appear in standard output logs. However, access logs are only present if you
apply a Message Logging policy.

<table><colgroup><col> <col> <col></colgroup><tbody><tr><td><div><div><p><span><a href="#linux"><img src="https://docs.mulesoft.com/gateway/1.12/_images/install-linux-logo.png" alt="20%" width="20%"></a></span></p></div></div></td><td><div><div><p><span><a href="#docker"><img src="https://docs.mulesoft.com/gateway/1.12/_images/install-docker-logo.png" alt="25%" width="25%"></a></span></p></div></div></td><td><div><div><p><span><a href="#kubernetes"><img src="https://docs.mulesoft.com/gateway/1.12/_images/install-kubernetes-logo.png" alt="20%" width="20%"></a></span></p></div></div></td></tr><tr><td><div><div><p><a href="#linux">Configure Log Output for Flex Gateway as a Linux Service</a></p></div></div></td><td><div><div><p><a href="#docker">Configure Log Output for Flex Gateway in a Docker Container</a></p></div></div></td><td><div><div><p><a href="#kubernetes">Configure Log Output for Flex Gateway in a Kubernetes Cluster</a></p></div></div></td></tr></tbody></table>

## Before You Begin

Before configuring Flex Gateway log output, complete the following tasks:

- [Download Flex Gateway](https://docs.mulesoft.com/gateway/1.12/flex-install)

- [Register and Run Flex Gateway](https://docs.mulesoft.com/gateway/1.12/flex-local-reg-run)

Additionally, depending on your output, ensure that the service where you direct logs to is
operational and that you have the necessary information:

- Splunk:

  - A running [Splunk](https://www.splunk.com/) service. You can test Splunk with a free Splunk
    Cloud trial.

  - Added an HTTP Event Collector (HEC) data input to the Cloud or Enterprise Splunk service. See
    the
    [Splunk documentation](https://docs.splunk.com/Documentation/Splunk/7.0.3/Data/UsetheHTTPEventCollector)
    about how to add a data input, and how to create an HEC token.

- Dynatrace:

  - A running [Dynatrace](https://www.dynatrace.com/) service. You can test Dynatrace with a free
    Dynatrace trial.

  - Environment ID. To find your Dynatrace environment ID, see
    [Environment ID](https://www.dynatrace.com/support/help/get-started/monitoring-environment/environment-id)

  - Access token. To generate a Dynatrace access token, see
    [Access Tokens](https://www.dynatrace.com/support/help/manage/access-control/access-tokens).
    Ensure that the token has the `Ingest logs` token scope.

## Runtime Logs and Access Logs

Runtime and access logs both appear in the same log output. However, you can choose whether to
include both logs in your log output. To use access logs, you must also apply a Message Logging
policy.

### Runtime Logs

Runtime logs include the following information:

- The startup and shutdown of Flex Gateway, Fluent Bit, and Envoy

- Deployed APIs and policies

- Possible misconfigurations of Flex Gateway or other errors

### Access Logs

Access logs describe incoming interaction with Envoy over a period of time and incoming requests and
responses for specific APIs.

To enable access logs, you must apply a Message Logging policy to the API instances you want to
monitor. To apply a Message Logging policy, see [Configuring Access Logs](#configure-access-logs).

## Logging Configuration File

The `logging` object configures the delivery of runtime and access logs enabled via the message
logging policy. Logs are delivered to any supported Fluent Bit v3.2.10 output.

```yaml
apiVersion: gateway.mulesoft.com/v1alpha1
kind: Configuration
metadata:
  name: <value>
  namespace: <namespace name>
spec:
  logging:
    outputs:
      - name: <output-name>
        type: <output-type>
        parameters:
          <param-name>: <param-value>
    runtimeLogs:
      logLevel: <value>
      outputs: <value>
    accessLogs:
      outputs: <value>
```

<table><colgroup><col> <col> <col> <col></colgroup><thead><tr><th>Parameter</th><th>Required or Optional</th><th>Default Value</th><th>Description</th></tr></thead><tbody><tr><td><p><code>logging.outputs[#].name</code></p></td><td><p>Required</p></td><td><p>N/A</p></td><td><p>The name of this output to later refer to in runtime and access logs configurations.</p></td></tr><tr><td><p><code>logging.outputs[#].type</code></p></td><td><p>Required</p></td><td><p>N/A</p></td><td><p>An output type supported by Fluent Bit. For Fluent Bit output types, see <a href="https://docs.fluentbit.io/manual">Fluent Bit documentation</a> for your Fluent Bit version.</p></td></tr><tr><td><p><code>logging.outputs[#].parameters</code></p></td><td><p>Required</p></td><td><p>N/A</p></td><td><p>A map of parameters for the specific Fluent Bit output type. For Fluent Bit output type parameters, see <a href="https://docs.fluentbit.io/manual">Fluent Bit documentation</a> for your Fluent Bit version.</p></td></tr><tr><td><p><code>logging.accessLogs.outputs</code></p></td><td><p>Optional</p></td><td><p>Empty</p></td><td><p>A list of output names to redirect access logs to.</p></td></tr><tr><td><p><code>logging.runtimeLogs.logLevel</code></p></td><td><p>Optional</p></td><td><p><code>info</code></p></td><td><p>A parameter specifying log detail. The supported <code>logLevel</code> types listed in decreasing verbosity are <code>debug</code>, <code>info</code>, <code>warn</code>, <code>error</code>, and <code>fatal</code>.</p></td></tr><tr><td><p><code>logging.runtimeLogs.outputs</code></p></td><td><p>Optional</p></td><td><p>Empty</p></td><td><p>A list of output names to redirect runtime logs to.</p></td></tr></tbody></table>

Leaving a value blank applies the default value to your configuration.

In addition to parameters above, Flex Gateway offers variables for logging output. When configured,
the variables render as one of their respective outputs in the logs:

<table><colgroup><col> <col> <col></colgroup><thead><tr><th>Variable</th><th>Description</th><th>Outputs</th></tr></thead><tbody><tr><td><p><code>date</code></p></td><td><p>Date and time of the logged event</p></td><td><p>A specific time, for example, <code>17/11/2022-09:48:27AM</code></p></td></tr><tr><td><p><code>logger</code></p></td><td><p>Flex Gateway service where the logged event occurred</p></td><td><p><code>flex-gateway-agent</code>, <code>flex-gateway-envoy</code>, and <code>flex-gateway-fluent</code></p></td></tr><tr><td><p><code>level</code></p></td><td><p><code>Loglevel</code> of the logged event</p></td><td><p><code>debug</code>, <code>info</code>, <code>warn</code>, <code>error</code>, or <code>fatal</code></p></td></tr><tr><td><p><code>kind</code></p></td><td><p>Log type</p></td><td><p><code>runtimeLog</code> or <code>accessLog</code></p></td></tr></tbody></table>

To view configuration files with applied values, see the following configuration file examples:

- [File Configuration Example](#file-configuration-example)

- [HTTP Configuration Example](#http-configuration-example)

- [Splunk Configuration Example](#splunk-configuration-example)

- [Dynatrace Configuration Example](#dynatrace-configuration-example)

## Configure Log Output for Flex Gateway as a Linux Service

1.  Create a YAML configuration file in the Flex Gateway configuration directory:

    ```ssh
    sudo touch /usr/local/share/mulesoft/flex-gateway/conf.d/logs-config.yaml
    ```

2.  Update the file with your desired output configuration details as shown in the following
    examples:

    - [File Configuration Example](#file-configuration-example)

    - [HTTP Configuration Example](#http-configuration-example)

    - [Splunk Configuration Example](#splunk-configuration-example)

    - [Dynatrace Configuration Example](#dynatrace-configuration-example)

      If no events appear in the logging output, check the Flex Gateway standard output logs for any
      configuration errors.

      To view standard output logs, see [View Logs](https://docs.mulesoft.com/gateway/1.12/flex-local-view-logs).

      For additional troubleshooting help, see
      [Troubleshooting Self-Managed Gateway Logging Issues](https://docs.mulesoft.com/gateway/1.12/flex-troubleshoot-logging).

3.  If you are configuring access logs, see [Configure Access Logs](#access-logs) to apply a Message
    Logging policy.

## Configure Log Output for Flex Gateway in a Docker Container

> [!NOTE] If you have already added a volume for a folder with your Flex Gateway configuration
> files, skip to the create and save a YAML file step.

1.  Press Ctrl+C to stop your Flex Gateway and any replicas.

2.  Restart your Flex Gateway with an additional volume for the configuration directory:

    ```ssh
    docker run --rm \
    -v "$(pwd)":/usr/local/share/mulesoft/flex-gateway/conf.d \
    -p 8080:8080 \
    mulesoft/flex-gateway
    ```

    > [!NOTE] Specify an optional name you want to assign to your Flex Replica by including the
    > following: `-e FLEX_NAME=<name-for-flex-replica> \`.

3.  Create and save a YAML file with your desired output configuration details as shown in the
    following examples:

    - [File Configuration Example](#file-configuration-example)

    - [HTTP Configuration Example](#http-configuration-example)

    - [Splunk Configuration Example](#splunk-configuration-example)

    - [Dynatrace Configuration Example](#dynatrace-configuration-example)

      If no events appear in the logging output, check the Flex Gateway standard output logs for any
      configuration errors.

      To view standard output logs, see [View Logs](https://docs.mulesoft.com/gateway/1.12/flex-local-view-logs).

      For additional troubleshooting help, see
      [Troubleshooting Self-Managed Gateway Logging Issues](https://docs.mulesoft.com/gateway/1.12/flex-troubleshoot-logging).

4.  If you are configuring access logs, see [Configure Access Logs](#access-logs) to apply a Message
    Logging policy.

## Configure Log Output for Flex Gateway in a Kubernetes Cluster

To configure logging for Flex Gateway:

1.  Create a new resource using a YAML configuration file with your desired output configuration
    details as shown in the following examples:

    - [File Configuration Example](#file-configuration-example)

    - [HTTP Configuration Example](#http-configuration-example)

    - [Splunk Configuration Example](#splunk-configuration-example)

    - [Dynatrace Configuration Example](#dynatrace-configuration-example)

      If no events appear in the logging output, check the Flex Gateway standard output logs for any
      configuration errors.

      To view standard output logs, see [View Logs](https://docs.mulesoft.com/gateway/1.12/flex-local-view-logs).

      For additional troubleshooting help, see
      [Troubleshooting Self-Managed Gateway Logging Issues](https://docs.mulesoft.com/gateway/1.12/flex-troubleshoot-logging).

2.  If you are configuring access logs, see [Configure Access Logs](#access-logs) to apply a Message
    Logging policy.

## File Configuration Example

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

```yaml
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: |
            [{date}][{logger}][{level}][{kind}] {message}
    runtimeLogs:
      logLevel: info
      outputs:
        - default
    accessLogs:
      outputs:
        - default
```

> [!NOTE] For Docker, in `spec.logging.output.parameters.file`, replace `/var/log` with the absolute
> path to the mounted configuration directory.

## HTTP Configuration Example

You can configure Flex Gateway to send formatted runtime and access logs to a `HTTP` output. As an
example, the following definition specifies a `spec.logging.outputs.type` value of `HTTP`:

```yaml
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
```

## Splunk Configuration Example

Splunk begins ingesting logs soon after you apply this resource.

```yaml
apiVersion: gateway.mulesoft.com/v1alpha1
kind: Configuration
metadata:
  name: splunk-config
spec:
  logging:
    outputs:
      - name: splunk
        type: splunk
        parameters:
          host: <instance-name>.splunkcloud.com
          port: "8088"
          splunk_token: <Splunk's HEC token>
          tls: "on"
          tls.verify: "off"
    runtimeLogs:
      logLevel: info
      outputs: [splunk]
    accessLogs:
      outputs: [splunk]
```

## Dynatrace Configuration Example

You can configure Flex Gateway to send formatted runtime and access logs to a Dynatrace environment
`HTTP` output. As an example, the following file contains the necessary configurations:

```yaml
apiVersion: gateway.mulesoft.com/v1alpha1
kind: Configuration
metadata:
  name: dynatrace-config
spec:
  logging:
    outputs:
      - name: dynatrace
        type: http
        parameters:
          host: <environmentID>.live.dynatrace.com
          Port: "443"
          allow_duplicated_headers: "false"
          header:
            - Content-Type application/json; charset=utf-8
            - Authorization Api-Token <accessToken>
          URI: /api/v2/logs/ingest
          Format: json
          json_date_key: timestamp
          json_date_format: iso8601
          tls: "on"
          tls.verify: "off"
    runtimeLogs:
      logLevel: info
      outputs:
        - dynatrace
    accessLogs:
      outputs:
        - dynatrace
```

For more information about configuration options, see the
[Fluent Bit documentation](https://docs.fluentbit.io/manual) for your Fluent Bit version.

## Configure Access Logs

To configure access logs in your log output, you must apply a Message Logging policy to the APIs
whose request and response data you want to monitor. If you have previously applied a Message
Logging policy to an API instance, you do not need to configure another.

Configuring a Message Logging policy makes access logs visible in both standard output logs and your
third-party log services.

To apply a Message Logging policy, see [Applying Policies in Local Mode](https://docs.mulesoft.com/gateway/1.12/flex-gateway-secure-local)
and use the [Message Logging Configuration Parameters](https://docs.mulesoft.com/gateway/latest/policies-included-message-logging).

If your access logs are not visible, it is possible that a policy with a higher execution order is
causing an error before the Message Logging policy can execute. To reorder policy execution, see
[Ordering Policies](https://docs.mulesoft.com/gateway/1.12/policies-reorder).

## Logging Event Examples

The following log output examples demonstrate possible outputs that may occur for the following
events:

- [Graceful shutdowns](#graceful-shutdowns)

- [Service disconnections](#service-disconnections)

- [Envoy crash](#envoy-crash)

### Graceful Shutdowns

\[flex-gateway-agent\]\[info\] SignalHandler: Signal terminated received
\[flex-gateway-agent\]\[info\] FilesystemWatcher(/usr/local/share/mulesoft/flex-gateway/conf.d):
Stopping with context done \[flex-gateway-agent\]\[info\] XdsService: Stopping with context done
\[flex-gateway-agent\]\[error\] flex-gateway-envoy: Stopped with error context canceled
\[flex-gateway-agent\]\[info\] FilesystemWatcher(/etc/mulesoft/flex-gateway/conf.d): Stopping with
context done \[flex-gateway-agent\]\[error\] flex-gateway-fluent: Stopped with error context
canceled \[flex-gateway-agent\]\[error\] flex-gateway-fluent: Stopped with error context canceled
\[flex-gateway-agent\]\[info\] Server dropped connection \[flex-gateway-agent\]\[info\] Agent
communication closed

### Service Disconnections

\[flex-gateway-agent\]\[error\] WebSocket receiver got error: read tcp
172.17.0.2:60780->100.64.1.37:443: i/o timeout \[flex-gateway-agent\]\[info\] Server dropped
connection \[flex-gateway-agent\]\[warn\] Dropped connection due to error read tcp
172.17.0.2:60780->100.64.1.37:443: i/o timeout \[flex-gateway-agent\]\[info\] Reconnecting after
connection was dropped \[flex-gateway-agent\]\[error\] Error connecting to Websocket Server: dial
tcp: lookup arm-mcm2-service.kstg.msap.io on 192.168.65.7:53: dial udp 192.168.65.7:53: connect:
network is unreachable

### Envoy Crash

\[flex-gateway-envoy\]\[critical\] Caught Segmentation fault, suspect faulting address
0xffff87e8fb89485b \[flex-gateway-envoy\]\[critical\] Backtrace (use tools/stack\_decode.py to get
line numbers): \[flex-gateway-envoy\]\[critical\] Envoy version:
36cbae1aeedd8c3b4eb88cd28268d21fe0905ce5/1.23.0/Clean/RELEASE/BoringSSL
\[flex-gateway-envoy\]\[critical\] #0: \_\_restore\_rt \[0x7ff79db2f140\]
\[flex-gateway-envoy\]\[critical\] #1: \[0x557dcfad249b\] \[flex-gateway-envoy\]\[critical\] #2:
\[0x557dcdf35237\] \[flex-gateway-envoy\]\[critical\] #3: \[0x557dce16d49f\]
\[flex-gateway-envoy\]\[critical\] #4: \[0x557dce1a8ff5\] \[flex-gateway-envoy\]\[critical\] #5:
\[0x557dce1a8e47\] \[flex-gateway-envoy\]\[critical\] #6: ... \[flex-gateway-agent\]\[error\]
flex-gateway-envoy: Stopped with error flex-gateway-envoy: command error: signal: segmentation fault
\[flex-gateway-agent\]\[error\] flex-gateway-fluent: Stopped with error context canceled
\[flex-gateway-agent\]\[error\] flex-gateway-fluent: Stopped with error context canceled
\[flex-gateway-agent\]\[info\] FilesystemWatcher(/etc/mulesoft/flex-gateway/conf.d): Stopping with
context done \[flex-gateway-agent\]\[info\]
FilesystemWatcher(/usr/local/share/mulesoft/flex-gateway/conf.d): Stopping with context done
\[flex-gateway-agent\]\[info\] XdsService: Stopping with context done \[flex-gateway-agent\]\[info\]
Server dropped connection \[flex-gateway-agent\]\[info\] Agent communication closed

## See Also

- [Message Logging Policy](https://docs.mulesoft.com/gateway/1.12/policies-included-message-logging)
