Creating a log group
-
In the management console
, select the folder where you want to create a log group. -
Select Cloud Logging.
-
Click Create group.
-
Optionally, enter a name and description for the log group. Follow these naming requirements:
- It must be from 2 to 63 characters long.
- It can only contain lowercase Latin letters, numbers, and hyphens.
- It must start with a letter and cannot end with a hyphen.
-
Set the log group record retention period.
-
Optionally, select a data stream or create a new one to which the records added to your log group will be redirected.
-
Click Create group.
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.
To create a log group, run this command:
yc logging group create \
--name=group \
--retention-period=1h \
--data-stream=<stream_ID>
Where:
-
--name: Log group name. -
--retention-period: Retention period for log group records. This is an optional parameter.You can only set the record retention period in hours, minutes, or seconds, e.g.,
1hor1440m. -
--data-stream: Data stream ID in Yandex Data Streams. This is an optional parameter. The specified stream will automatically receive the records added to your log group. A stream ID comprises the availability zone, folder ID, Yandex Managed Service for YDB database ID, and stream name.For example, your stream ID will appear as
/ru-central1/aoeu1kuk2dht********/cc8029jgtuab********/aws_streamif:aws_stream: Stream name.ru-central1: Availability zone.aoeu1kuk2dht********: Folder ID.cc8029jgtuab********: Yandex Managed Service for YDB database ID.
Result:
done (1s)
id: af3flf29t8**********
folder_id: aoek6qrs8t**********
cloud_id: aoegtvhtp8**********
created_at: "2023-06-24T09:56:38.970Z"
name: group
status: ACTIVE
retention_period: 3600s
data_stream: /ru-central1/aoeu1kuk2dht********/cc8029jgtuab********/aws_stream
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.
-
In the configuration file, describe the resources you want to create:
-
name: Log group name. This is an optional parameter. Use the following name format:- It must be from 2 to 63 characters long.
- It can only contain lowercase Latin letters, numbers, and hyphens.
- It must start with a letter and cannot end with a hyphen.
-
folder_id: Folder ID. This is an optional parameter. It defaults to the value defined by the provider. -
retention_period: Retention period for log group records. This is an optional parameter.You can only set the record retention period in hours, minutes, or seconds, e.g.,
1hor1440m.
Here is an example of the configuration file structure:
provider "yandex" { token = "<OAuth_token>" cloud_id = "<cloud_ID>" folder_id = "<folder_ID>" zone = "ru-central1-a" } resource "yandex_logging_group" "group1" { name = "<log_group_name>" folder_id = "<folder_ID>" retention_period = "5h" }For more information about the
yandex_logging_groupsettings, see this Terraform guide. -
-
Make sure the configuration files are correct.
-
In the command line, navigate to the directory where you created the configuration file.
-
Run a check using this command:
terraform plan
If the configuration description is correct, the terminal will display a list of the resources being created and their settings. If the configuration contains any errors, Terraform will point them out.
-
-
Deploy the cloud resources.
-
If the configuration does not contain any errors, run this command:
terraform apply -
Confirm creating the resources: type
yesin the terminal and press Enter.
This will create all the resources you need in the specified folder. You can check the new resources and their settings using the management console
or this CLI command:yc logging group list -
To create a log group, use the create REST API method for the LogGroup resource or the LogGroupService/Create gRPC API call.
Request example
The example below uses grpcurl. To run this example, authenticate with the API and clone the cloudapi
Create a file named payload.json:
{
"folder_id": "<folder_ID>",
"name": "new-group",
"description": "Description of a log group created with grpcurl",
"labels": {
"compute": "instance-logging"
}
}
Send this request:
grpcurl -rpc-header "Authorization: Bearer $(yc iam create-token)" \
-d @ \
-import-path ~/cloudapi/ \
-import-path ~/cloudapi/third_party/googleapis/ \
-proto ~/cloudapi/yandex/cloud/logging/v1/log_group_service.proto \
logging.api.cloud.yandex.net:443 yandex.cloud.logging.v1.LogGroupService.Create < payload.json
Response:
{
"id": "e23nitus5cg9********",
"description": "Create log group",
"createdAt": "2023-11-23T14:54:23.077532292Z",
"createdBy": "ajeugsk5ubk6********",
"modifiedAt": "2023-11-23T14:54:23.077532292Z",
"metadata": {
"@type": "type.googleapis.com/yandex.cloud.logging.v1.CreateLogGroupMetadata",
"logGroupId": "e23pjn86385t********"
}
}