// POST https://composer.googleapis.com/v1/{parent=projects/*/locations/*}/environments{"name":"projects/example-project/locations/us-central1/environments/example-environment","config":{"dataRetentionConfig":{"taskLogsRetentionConfig":{"storageMode":"CLOUD_LOGGING_AND_CLOUD_STORAGE"}}}}
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["難以理解","hardToUnderstand","thumb-down"],["資訊或程式碼範例有誤","incorrectInformationOrSampleCode","thumb-down"],["缺少我需要的資訊/範例","missingTheInformationSamplesINeed","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-08-29 (世界標準時間)。"],[[["\u003cp\u003eThis page provides instructions on how to enable or disable saving Airflow task logs to an environment's bucket within Cloud Composer 2.\u003c/p\u003e\n"],["\u003cp\u003eStarting from Cloud Composer version 2.8.0, task logs are stored in Cloud Logging by default, but you can choose to save them in both Cloud Logging and the environment's bucket.\u003c/p\u003e\n"],["\u003cp\u003eEnabling or disabling this feature can be done using Google Cloud CLI, Cloud Composer API, or Terraform, however it cannot be done through the Google Cloud console.\u003c/p\u003e\n"],["\u003cp\u003eWhen enabling this feature, previously logged data will still remain in Cloud Logging, and if you disable it later, logs already saved to the environment's bucket are not automatically deleted.\u003c/p\u003e\n"],["\u003cp\u003eThe configurations for saving logs remain unchanged during environment upgrades, so if an environment was set to save to the environment's bucket, it will continue doing so after the upgrade.\u003c/p\u003e\n"]]],[],null,["# Enable saving logs to the environment's bucket\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\n[Cloud Composer 3](/composer/docs/composer-3/enable-saving-logs-to-environment-bucket \"View this page for Cloud Composer 3\") \\| **Cloud Composer 2** \\| Cloud Composer 1\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\nThis page explains how to enable saving Airflow task logs to the environment's\nbucket for a new or existing environment.\n\nAs an option, you can enable the synchronization of task logs to the\nenvironment's bucket.\n\nAbout saving logs to the environment's bucket\n---------------------------------------------\n\nSaving logs to the environment's bucket works in the following way:\n\n- **Disabled (default)**: Task logs are available in Cloud Logging. You\n can view them in Airflow UI and in Cloud Logging. Task log files\n aren't saved to the environment's bucket.\n\n If saving logs to the environment's bucket was disabled and you\n enable it, task logs displayed in Airflow UI **don't show log entries**\n that were generated while logs were saved only to Cloud Logging. These\n logs aren't lost, they are still available in Cloud Logging.\n- **Enabled**: Task logs are saved both to Cloud Logging and to\n the environment's bucket. You can view them in Airflow UI and in\n Cloud Logging. Environment's bucket stores files with these logs.\n\n If saving logs to the environment's bucket was enabled and you\n disable it, the logs that were already saved to the environment's bucket\n aren't deleted and remain stored in the bucket.\n\nBefore you begin\n----------------\n\n- Starting from Cloud Composer version 2.8.0, all environments don't\n store task logs in the environment's bucket by default. Task logs are still\n available in Cloud Logging and Airflow UI.\n\n- When you upgrade your environment, the configuration for saving logs in the\n environment's bucket is not changed. For example, if you upgrade an\n environment that saved logs to the environment's bucket to a later version,\n the environment keeps saving logs to the environment's bucket.\n\n- To enable or disable this option, you can use Google Cloud CLI,\n Cloud Composer API, or Terraform. It is not possible to change this option\n through Google Cloud console.\n\nEnable or disable saving task logs to the environment's bucket when creating an environment\n-------------------------------------------------------------------------------------------\n\n### gcloud\n\nWhen you create an environment, the following arguments specify how Airflow\ntask logs must be saved:\n\n- `--disable-logs-in-cloud-logging-only` argument enables saving Airflow task logs to the environment's bucket.\n- `--enable-logs-in-cloud-logging-only` argument disables saving Airflow task logs to the environment's bucket. Logs are saved only to Cloud Logging.\n\n gcloud composer environments create \u003cvar translate=\"no\"\u003eENVIRONMENT_NAME\u003c/var\u003e \\\n --location \u003cvar translate=\"no\"\u003eLOCATION\u003c/var\u003e \\\n --disable-logs-in-cloud-logging-only\n\nReplace the following:\n\n- `ENVIRONMENT_NAME`: the name of your environment.\n- `LOCATION`: the region where the environment is located.\n\nExample: \n\n gcloud composer environments create example-environment \\\n --location us-central1 \\\n --disable-logs-in-cloud-logging-only\n\n### API\n\nWhen you create an environment, in the [Environment](/composer/docs/reference/rest/v1/projects.locations.environments#Environment)\n\\\u003e [EnvironmentConfig](/composer/docs/reference/rest/v1/projects.locations.environments#EnvironmentConfig) \\\u003e\n[DataRetentionConfig](/composer/docs/reference/rest/v1/projects.locations.environments#dataretentionconfig) \\\u003e\n[TaskLogsRetentionConfig](/composer/docs/reference/rest/v1/projects.locations.environments#tasklogsretentionconfig) resource,\nspecify how Airflow task logs must be saved:\n\n- `CLOUD_LOGGING_AND_CLOUD_STORAGE` to save logs to the environment's bucket and Cloud Logging.\n- `CLOUD_LOGGING_ONLY` to save logs only in Cloud Logging.\n\n {\n \"name\": \"projects/\u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e/locations/\u003cvar translate=\"no\"\u003eLOCATION\u003c/var\u003e/environments/\u003cvar translate=\"no\"\u003eENVIRONMENT_NAME\u003c/var\u003e\",\n \"config\": {\n \"dataRetentionConfig\": {\n \"taskLogsRetentionConfig\": {\n \"storageMode\": \"CLOUD_LOGGING_AND_CLOUD_STORAGE\"\n }\n }\n }\n }\n\nReplace the following:\n\n- `ENVIRONMENT_NAME`: the name of your environment.\n- `LOCATION`: the region where the environment is located.\n- `PROJECT_ID`: the [Project ID](/resource-manager/docs/creating-managing-projects).\n\nExample: \n\n // POST https://composer.googleapis.com/v1/{parent=projects/*/locations/*}/environments\n\n {\n \"name\": \"projects/example-project/locations/us-central1/environments/example-environment\",\n \"config\": {\n \"dataRetentionConfig\": {\n \"taskLogsRetentionConfig\": {\n \"storageMode\": \"CLOUD_LOGGING_AND_CLOUD_STORAGE\"\n }\n }\n }\n }\n\n### Terraform\n\nWhen you create an environment, the `storage_mode` field in the\n`task_logs_retention_config` block specifies how Airflow task logs must be\nsaved:\n\n- `CLOUD_LOGGING_AND_CLOUD_STORAGE` to save logs to the environment's bucket and Cloud Logging.\n- `CLOUD_LOGGING_ONLY` to save logs only in Cloud Logging.\n\n resource \"google_composer_environment\" \"example\" {\n provider = google-beta\n name = \"\u003cvar translate=\"no\"\u003eENVIRONMENT_NAME\u003c/var\u003e\"\n region = \"\u003cvar translate=\"no\"\u003eLOCATION\u003c/var\u003e\"\n\n config {\n\n data_retention_config {\n\n task_logs_retention_config {\n\n storage_mode = \"CLOUD_LOGGING_AND_CLOUD_STORAGE\"\n\n }\n }\n }\n\nReplace the following:\n\n- `ENVIRONMENT_NAME`: the name of your environment.\n- `LOCATION`: the region where the environment is located.\n\nExample: \n\n resource \"google_composer_environment\" \"example\" {\n provider = google-beta\n name = \"example-environment\"\n region = \"us-central1\"\n\n config {\n\n data_retention_config {\n\n task_logs_retention_config {\n\n storage_mode = \"CLOUD_LOGGING_AND_CLOUD_STORAGE\"\n\n }\n }\n }\n }\n\nEnable or disable saving task logs to the environment's bucket for an existing environment\n------------------------------------------------------------------------------------------\n\n### gcloud\n\nWhen you update an environment, the following arguments enable or disable\nsaving Airflow task logs to the environment's bucket:\n\n- `--disable-logs-in-cloud-logging-only` argument enables saving Airflow task logs to the environment's bucket. Logs are saved to the environment's bucket and to Cloud Logging.\n- `--enable-logs-in-cloud-logging-only` argument disables saving Airflow task logs to the environment's bucket. Logs are saved only to Cloud Logging.\n\nTo save Airflow logs in the environment's bucket: \n\n gcloud composer environments update \u003cvar translate=\"no\"\u003eENVIRONMENT_NAME\u003c/var\u003e \\\n --location \u003cvar translate=\"no\"\u003eLOCATION\u003c/var\u003e \\\n --disable-logs-in-cloud-logging-only\n\nReplace the following:\n\n- `ENVIRONMENT_NAME`: the name of your environment.\n- `LOCATION`: the region where the environment is located.\n\nExample: \n\n gcloud composer environments update example-environment \\\n --location us-central1 \\\n --disable-logs-in-cloud-logging-only\n\n### API\n\n1. Construct an [`environments.patch`](/composer/docs/reference/rest/v1/projects.locations.environments/patch) API request.\n\n2. In this request:\n\n 1. In the `updateMask` parameter, specify the\n `config.dataRetentionConfig.taskLogsRetentionConfig.storageMode`\n mask.\n\n 2. In the request body, specify how Airflow task logs must be\n saved:\n\n - `CLOUD_LOGGING_AND_CLOUD_STORAGE` to save logs to the environment's bucket and Cloud Logging.\n - `CLOUD_LOGGING_ONLY` to save logs only in Cloud Logging.\n\n {\n \"config\": {\n \"dataRetentionConfig\": {\n \"taskLogsRetentionConfig\": {\n \"storageMode\": \"CLOUD_LOGGING_AND_CLOUD_STORAGE\"\n }\n }\n }\n }\n\nExample: \n\n // PATCH https://composer.googleapis.com/v1/projects/example-project/\n // locations/us-central1/environments/example-environment?updateMask=\n // config.dataRetentionConfig.taskLogsRetentionConfig.storageMode\n\n {\n \"config\": {\n \"dataRetentionConfig\": {\n \"taskLogsRetentionConfig\": {\n \"storageMode\": \"CLOUD_LOGGING_AND_CLOUD_STORAGE\"\n }\n }\n }\n }\n\n### Terraform\n\nIn the `task_logs_retention_config` block, in the `storage_mode` field specify how Airflow task logs must be saved:\n\n- `CLOUD_LOGGING_AND_CLOUD_STORAGE` to save logs to the environment's bucket and Cloud Logging.\n- `CLOUD_LOGGING_ONLY` to save logs only in Cloud Logging.\n\n resource \"google_composer_environment\" \"example\" {\n provider = google-beta\n name = \"\u003cvar translate=\"no\"\u003eENVIRONMENT_NAME\u003c/var\u003e\"\n region = \"\u003cvar translate=\"no\"\u003eLOCATION\u003c/var\u003e\"\n\n config {\n\n data_retention_config {\n\n task_logs_retention_config {\n\n storage_mode = \"CLOUD_LOGGING_AND_CLOUD_STORAGE\"\n\n }\n }\n }\n\nReplace the following:\n\n- `ENVIRONMENT_NAME`: the name of your environment.\n- `LOCATION`: the region where the environment is located.\n\nExample: \n\n resource \"google_composer_environment\" \"example\" {\n provider = google-beta\n name = \"example-environment\"\n region = \"us-central1\"\n\n config {\n\n data_retention_config {\n\n task_logs_retention_config {\n\n storage_mode = \"CLOUD_LOGGING_AND_CLOUD_STORAGE\"\n\n }\n }\n }\n }\n\nWhat's next\n-----------\n\n- [View logs](/composer/docs/composer-2/view-logs)\n- [Monitor environments](/composer/docs/composer-2/monitor-environments)"]]