Getting started with Cloud Logging
In this tutorial, you'll add records to a log group and then view them.
Getting started
To get started in Yandex Cloud:
- Log in to the management console
. If you do not have an account yet, go to the management console and follow the guide. - On the Billing
page, make sure you have a billing account linked and it has theACTIVE
orTRIAL_ACTIVE
status. If you do not yet have a billing account, create one. - If you do not have a folder yet, create one.
Add records to a log group
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.
To add records to a log group, run the command:
-
Linux, MacOS:
yc logging write \ --group-name=default \ --message="My message" \ --level=INFO \ --json-payload='{"request_id": "1234"}'
-
Windows (cmd):
yc logging write ^ --group-name=default ^ --message="My message" ^ --level=INFO ^ --json-payload="{"request_id": "1234"}"
-
Windows (PowerShell):
yc logging write ` --group-name=default ` --message="My message" ` --level=INFO ` --json-payload='"{ \"request_id\": \"1234\" }"'
Where:
--group-name
: Name of the log group to add records to. If this parameter is not specified, records are added to the default log group in the current folder.--message
: Message.--level
: Logging level.--json-payload
: Additional information in JSON format.
To add entries to the log group, use the LogIngestionService/Write gRPC API call.
View the records
The log uses UTC
- In the management console
, select the folder containing your log group. - Select Cloud Logging.
- Click the row with the log group you want to view.
- The page that opens will show the log group records.
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.
When viewing the log, you can set a specific interval using the --since
and --until
flags. If no time interval is specified, information for the previous hour is displayed.
The following flags are used:
--since
: Time N and later.--until
: Time N and earlier.
If you only specify one flag, information is displayed for the hour before or after N depending on the flag.
Allowed time formats:
HH:MM:SS
. Example:15:04:05
.- RFC-3339
. Example:2006-01-02T15:04:05Z
,2h
,3h30m ago
.
To access a log group, use its name or unique ID. To find them, get a list of log groups in the folder. If you don't specify the name or ID, records are returned from the default log group in the current folder.
You can limit the number of records returned using the --limit
flag. Acceptable values are from 1 to 1000.
To view the records in JSON format, run the command:
yc logging read --group-name=default --format=json
Result:
[
{
"uid": "488ece3c-75b8-4d35-95ac-2b49********",
"resource": {},
"timestamp": "2023-06-22T02:10:40Z",
"ingested_at": "2023-06-22T08:49:15.716Z",
"saved_at": "2023-06-22T08:49:16.176097Z",
"level": "INFO",
"message": "My message",
"json_payload": {
"request_id": "1234"
}
}
]
To read records as they appear, use the --follow
flag:
yc logging read --group-name=default --follow
This command will display records from the most recent hour and will continue to return new records until you terminate it by pressing Ctrl + C. The --follow
flag is incompatible with --since
and --until
.
To view log group entries, use the LogReadingService/Read gRPC API call.