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
, go the folder containing the API gateway. - In the list of services, select API Gateway.
- Select the API gateway you want to configure logging for.
- At the top of the page, click
Edit. - Under Logging, select the following in the Destination field:
Not specified
: To disable logging.Folder
: To write logs to the default log group for the folder containing the API gateway.- (Optional) In the Min. logging level field, select the minimum logging level.
Log group
: To write logs to a custom log group.- (Optional) In the Min. logging level field, select the minimum logging level.
- In the Log group field, select the log group to write the logs to. If you do not have a log group, create one.
- 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 command line interface yet, install and initialize it.
The folder specified in the CLI profile is used by default. You can specify a different folder 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 modifying an API gateway. The log group must reside in the same folder as the API gateway.
Minimum logging level
To set a minimum logging level, provide it in the --min-log-level
parameter when creating or modifying 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 modifying 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: d5dr8k465604********.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 documentation on the Terraform
If you don't have Terraform, 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 modifying an API gateway. The log group must reside in the same folder as the API gateway.
Minimum logging level
To set a minimum logging level, provide it in the log_group_id
parameter under log_options
when creating or modifying 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 modifying 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 the
yandex_api_gateway
resource parameters in Terraform, see the relevant provider documentation . -
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 parameters. No changes will be made at this step. If the configuration contains any errors, Terraform will point them out.
-
Apply the configuration changes:
terraform apply
-
Confirm the changes: type
yes
into the terminal and press Enter.
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.