Writing to the execution log in API Gateway
Note
Logging is not free of charge. For more information, see the Yandex Cloud Logging documentation.
-
In the management console
, navigate to the folder containing the API gateway. -
In the list of services, select API Gateway.
-
Select the API gateway for which you want to configure logging.
-
At the top of the page, click
Edit. -
Under Logging:
-
Click Save.
If you set the minimum logging level, logs of that level and higher will be written to the execution log. With no minimum logging level set, all API gateway logs will be written to the execution log.
If you do not have the Yandex Cloud CLI installed yet, install and initialize it.
By default, the CLI uses the folder specified when creating the profile. To change the default folder, use the yc config set folder-id <folder_ID> command. You can also set a different folder for any specific command using the --folder-name or --folder-id parameter.
Logging destination
If a custom log group is not specified in the API gateway parameters or logging is not turned off, the API gateway automatically writes all logs to the default log group for the folder it resides in.
For logging to another folder's default log group, provide that folder's ID in the --log-folder-id parameter when creating or updating an API gateway. The account used to run the command must have the logging.editor role or higher for the folder.
For logging to a custom log group, provide that log group's ID in the --log-group-id parameter when creating or updating an API gateway. The log group may reside in a different folder. The account used to run the command must have the logging.editor role or higher for the folder.
Minimum logging level
To set the minimum logging level, specify it in the --min-log-level parameter when creating or updating an API gateway.
If you set the minimum logging level, logs of that level and higher will be written to the execution log. With no minimum logging level set, all API gateway logs will be written to the execution log.
Disabling logging
To disable logging, set the --no-logging parameter when creating or updating an API gateway.
Command example
For logging to a custom log group, run this command:
yc serverless api-gateway update <API_gateway_name_or_ID> \
--log-group-id <log_group_ID> \
--min-log-level <minimum_logging_level>
Where:
--log-group-id: ID of the log group to write logs to.--min-log-level: Minimum logging level. The available levels areTRACE,DEBUG,INFO,WARN,ERROR, andFATAL. This is an optional parameter.
Result:
id: d5dr8k465604********
folder_id: b1g3f9i71bpm********
created_at: "2024-01-26T09:18:55.985Z"
name: example_gateway
status: ACTIVE
domain: d5dm1lba80md********.i9******.apigw.yandexcloud.net
log_group_id: ckgsh1kdbvj1********
connectivity: {}
log_options:
log_group_id: e23u2vn449av********
min_level: ERROR
With Terraform
Terraform is distributed under the Business Source License
For more information about the provider resources, see the relevant documentation on the Terraform
If you do not have Terraform yet, install it and configure the Yandex Cloud provider.
Logging destination
If a custom log group is not specified in the API gateway parameters or logging is not turned off, the API gateway automatically writes all logs to the default log group for the folder it resides in.
For logging to another folder's default log group, provide that folder's ID under log_options in the folder_id parameter when creating or updating an API gateway. The account used to run the command must have the logging.editor role or higher for the folder.
For logging to a custom log group, provide that log group's ID under log_options in the log_group_id parameter when creating or updating an API gateway. The log group may reside in a different folder. The account used to run the command must have the logging.editor role or higher for the folder.
Minimum logging level
To set the minimum logging level, specify it under log_options in the min_level parameter when creating or updating an API gateway.
If you set the minimum logging level, logs of that level and higher will be written to the execution log. With no minimum logging level set, all API gateway logs will be written to the execution log.
Disabling logging
To disable logging, under log_options, set the disabled parameter to true when creating or updating an API gateway.
Example
For logging to a custom log group:
-
Open the Terraform configuration file and add the
log_optionssection to theyandex_api_gatewayresource description:Here is an example of the configuration file structure:
resource "yandex_api_gateway" "<API_gateway_name>" { ... log_options { folder_id = "<folder_ID>" min_level = "<minimum_logging_level>" } ... }Where:
folder_id: Folder ID.min_level: Minimum logging level. The available levels areTRACE,DEBUG,INFO,WARN,ERROR, andFATAL. This is an optional parameter.
For more information about
yandex_api_gatewayproperties in Terraform, see this Terraform article. -
Check the configuration using this command:
terraform validateIf the configuration is correct, you will get this message:
Success! The configuration is valid. -
Run this command:
terraform planYou will see a detailed list of resources. No changes will be made at this step. If the configuration contains any errors, Terraform will show them.
-
Apply the changes:
terraform apply -
Type
yesand press Enter to confirm the changes.
For logging to the execution log in Yandex API Gateway, use the update REST API method for the ApiGateway resource or the ApiGatewayService/Update gRPC API call.