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.
To write logs to a custom log group, provide the log group ID in the --log-group-id
parameter when creating or updating an API gateway. The log group must reside in the same folder as the API gateway.
Minimum logging level
To set the minimum logging level, provide 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
To write logs 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.
To write logs to a custom log group, under log_options
, provide the log group ID in the log_group_id
parameter when creating or updating an API gateway. The log group must reside in the same folder as the API gateway.
Minimum logging level
To set the minimum logging level, provide it in the log_group_id
parameter under log_options
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
To write logs to a custom log group:
-
Open the Terraform configuration file and add the
log_options
section to theyandex_api_gateway
resource 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_gateway
properties in Terraform, see this Terraform article . -
Check the configuration using this command:
terraform validate
If the configuration is correct, you will get this message:
Success! The configuration is valid.
-
Run this command:
terraform plan
The terminal will display a list of resources with their properties. No changes will be made at this step. If the configuration contains any errors, Terraform will point them out.
-
Apply the changes:
terraform apply
-
Type
yes
and press Enter to confirm the changes.
To write 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.