[Yandex Cloud documentation](../../index.md) > [Yandex Managed Service for Apache Airflow™](../index.md) > [Step-by-step guides](index.md) > Logs and monitoring > Transferring logs from Apache Airflow™ to Cloud Logging

# Transferring Managed Service for Apache Airflow™ cluster logs to Yandex Cloud Logging

You can set up regular collection of Managed Service for Apache Airflow™ cluster performance logs. Logs will be delivered to a [log group](../../logging/concepts/log-group.md) in Cloud Logging. You can choose between these two types of log groups:

* Default log group of the cluster folder.
* Custom log group.

## Transferring data to the default log group {#default}

1. [Assign](../../iam/operations/sa/assign-role-for-sa.md) the `managed-airflow.integrationProvider` [role](../../iam/roles-reference.md#managed-airflow-integrationProvider) to the cluster service account.
1. Configure logging in the Managed Service for Apache Airflow™ cluster:

   {% list tabs group=instructions %}

   * Management console {#console}

      1. Open the [folder dashboard](https://console.yandex.cloud).
      1. Navigate to **Managed Service for&nbsp;Apache&nbsp;Airflow™**.
      1. Select your cluster and click **Edit** in the top panel.
      1. Under **Logging**, enable **Write logs**.
      1. To write logs to the default log group, select **Folder** in the **Destination** field.
      1. Specify the folder whose log group you want to use.
      1. Select the minimum logging level.

         The execution log will contain logs of this level or higher. The available levels are `TRACE`, `DEBUG`, `INFO`, `WARN`, `ERROR`, and `FATAL`. The default is `INFO`.

   * CLI {#cli}

      Specify the following logging parameters in the cluster create command:

      ```bash
      yc managed-airflow cluster update \
         ...
         --log-enabled \
         --log-folder-id <folder_ID> \
         --log-min-level <logging_level>
      ```

      Specify the folder whose log group you want to use.

      The execution log will contain logs of this level or higher. The available levels are `TRACE`, `DEBUG`, `INFO`, `WARN`, `ERROR`, and `FATAL`. The default is `INFO`.

   * Terraform {#tf}

      Specify the following parameters in the configuration file with the cluster description:

      ```hcl
      resource "yandex_airflow_cluster" "<cluster_name>" {
        ...
        logging = {
          enabled   = true
          folder_id = "<folder_ID>"
          min_level = "<logging_level>"
        }
      }
      ```

      Specify the folder whose log group you want to use.

      The execution log will contain logs of this level or higher. The available levels are `TRACE`, `DEBUG`, `INFO`, `WARN`, `ERROR`, and `FATAL`. The default is `INFO`.

   * API {#api}

      In the body of the cluster update request ([Cluster.Update](../api-ref/Cluster/update.md) in the REST API or [ClusterService.Update](../api-ref/grpc/Cluster/update.md) in the gRPC API), specify the following parameters:

      ```json
      {
         ...
         "logging": {
            "enabled": true,
            "minLevel": "<logging_level>",
            "folderId": "<folder_ID>"
         }
      }
      ```

      Specify the folder whose log group you want to use.

      The execution log will contain logs of this level or higher. The available levels are `TRACE`, `DEBUG`, `INFO`, `WARN`, `ERROR`, and `FATAL`. The default is `INFO`.

   {% endlist %}

1. Test the transfer of cluster logs to the log group:

   {% list tabs group=instructions %}

   * Management console {#console}

      1. In the management console, navigate to the relevant folder.
      1. Navigate to **Cloud Logging**.
      1. Click the row with the `default` log group.

      The page that opens will show the log group entries.

   * CLI {#cli}

      To view the entries in JSON format, run this command:

      ```bash
      yc logging read --group-name=default --format=json
      ```

      Result:

      ```text
      [
        {
          "uid": "3:74********",
          "resource": {
            "type": "managed-airflow.cluster",
            "id": "c9qv4tnjqdpa********"
          },
          "timestamp": "2024-10-31T11:14:53.740223Z",
          "ingested_at": "2024-10-31T11:14:55.633Z",
          "saved_at": "2024-10-31T11:14:57.231685Z",
          "level": "INFO",
          "message": "10.253.244.40 - - \"GET /health HTTP/1.1\" 200 283 \"-\" \"kube-probe/1.25\"",
          "json_payload": {
            "file": "/home/airflow/.local/lib/python3.8/site-packages/gunicorn/glogging.py",
            "instance": "airflow-c9qv4tnjqdpa********-webserver-68********-q5***",
            "line": 363,
            "resource_id": "c9qv4tnjqdpa********",
            "stream_name": "webserver",
            "thread": "MainThread"
          },
          "stream_name": "webserver"
        }
      ]
      ```

   * API {#api}

      To view log group entries, use the [LogReadingService.Read](../../logging/api-ref/grpc/LogReading/read.md) gRPC API call.

   {% endlist %}

   For more information, see [Reading records](../../logging/operations/read-logs.md).

## Sending data to a custom log group {#custom}

1. [Create a log group](../../logging/operations/create-group.md) named `airflow-log-group`.
1. [Assign](../../iam/operations/sa/assign-role-for-sa.md) the `managed-airflow.integrationProvider` [role](../../iam/roles-reference.md#managed-airflow-integrationProvider) to the cluster service account.
1. Configure logging in the Managed Service for Apache Airflow™ cluster:

   {% list tabs group=instructions %}

   * Management console {#console}

      1. Open the [folder dashboard](https://console.yandex.cloud).
      1. Navigate to **Managed Service for&nbsp;Apache&nbsp;Airflow™**.
      1. Select your cluster and click **Edit** in the top panel.
      1. Under **Logging**, enable **Write logs**.
      1. To write logs to a custom log group, select **Log group** in the **Destination** field.
      1. Specify the `airflow-log-group` log group.
      1. Select the minimum logging level.

         The execution log will contain logs of this level or higher. The available levels are `TRACE`, `DEBUG`, `INFO`, `WARN`, `ERROR`, and `FATAL`. The default is `INFO`.

   * CLI {#cli}

      Specify the following logging parameters in the cluster create command:

      ```bash
      yc managed-airflow cluster create \
         ...
         --log-enabled \
         --log-group-id <log_group_ID> \
         --log-min-level <logging_level>
      ```

      The execution log will contain logs of this level or higher. The available levels are `TRACE`, `DEBUG`, `INFO`, `WARN`, `ERROR`, and `FATAL`. The default is `INFO`.

   * Terraform {#tf}

      Specify the following parameters in the configuration file with the cluster description:

      ```hcl
      resource "yandex_airflow_cluster" "<cluster_name>" {
        ...
        logging = {
          enabled      = true
          log_group_id = "<log_group_ID>"
          min_level    = "<logging_level>"
        }
      }
      ```

      The execution log will contain logs of this level or higher. The available levels are `TRACE`, `DEBUG`, `INFO`, `WARN`, `ERROR`, and `FATAL`. The default is `INFO`.

   * API {#api}

      In the body of the cluster update request ([Cluster.Update](../api-ref/Cluster/update.md) in the REST API or [ClusterService.Update](../api-ref/grpc/Cluster/update.md) in the gRPC API), specify the following parameters:

      ```json
      {
         ...
         "logging": {
            "enabled": true,
            "minLevel": "<logging_level>",
            "logGroupId": "<log_group_ID>"
         }
      }
      ```

      The execution log will contain logs of this level or higher. The available levels are `TRACE`, `DEBUG`, `INFO`, `WARN`, `ERROR`, and `FATAL`. The default is `INFO`.

   {% endlist %}

1. Test the transfer of cluster logs to the log group:

   {% list tabs group=instructions %}

   * Management console {#console}

      1. In the management console, navigate to the relevant folder.
      1. Navigate to **Cloud Logging**.
      1. Click the row with the `airflow-log-group` log group.

      The page that opens will show the records.

   * CLI {#cli}

      To view the entries in JSON format, run this command:

      ```bash
      yc logging read --group-name=airflow-log-group --format=json
      ```

      Result:

      ```text
      [
        {
          "uid": "3:74********",
          "resource": {
            "type": "managed-airflow.cluster",
            "id": "c9qv4tnjqdpa********"
          },
          "timestamp": "2024-10-31T11:14:53.740223Z",
          "ingested_at": "2024-10-31T11:14:55.633Z",
          "saved_at": "2024-10-31T11:14:57.231685Z",
          "level": "INFO",
          "message": "10.253.244.40 - - \"GET /health HTTP/1.1\" 200 283 \"-\" \"kube-probe/1.25\"",
          "json_payload": {
            "file": "/home/airflow/.local/lib/python3.8/site-packages/gunicorn/glogging.py",
            "instance": "airflow-c9qv4tnjqdpa********-webserver-68********-q5***",
            "line": 363,
            "resource_id": "c9qv4tnjqdpa********",
            "stream_name": "webserver",
            "thread": "MainThread"
          },
          "stream_name": "webserver"
        }
      ]
      ```

   * API {#api}

      To view log group entries, use the [LogReadingService.Read](../../logging/api-ref/grpc/LogReading/read.md) gRPC API call.

   {% endlist %}

   For more information, see [Reading records](../../logging/operations/read-logs.md).