StreamLogs
Retrieves a log stream for a cluster.
This method is similar to ListLogs, but uses server-side streaming, which allows for the tail -f
command semantics.
- TypeScript
- Python
import { cloudApi, serviceClients, Session } from "@yandex-cloud/nodejs-sdk";
const StreamClusterLogsRequest =
cloudApi.mdb.clickhouse_cluster_service.StreamClusterLogsRequest;
const StreamClusterLogsRequest_ServiceType =
cloudApi.mdb.clickhouse_cluster_service.StreamClusterLogsRequest_ServiceType;
(async () => {
const authToken = process.env["YC_OAUTH_TOKEN"];
const session = new Session({ oauthToken: authToken });
const client = session.client(serviceClients.ClusterServiceClient);
const result = await client.streamLogs(
StreamClusterLogsRequest.fromPartial({
clusterId: "clusterId",
// columnFilter: ["columnFilter"],
serviceType: StreamClusterLogsRequest_ServiceType.CLICKHOUSE,
// fromTime: {
// seconds: 0,
// nanos: 0
// },
// toTime: {
// seconds: 0,
// nanos: 0
// },
// recordToken: "recordToken",
// filter: "filter"
})
);
console.log(result);
})();
import os
import grpc
import yandexcloud
from yandex.cloud.dataproc.v1.cluster_service_pb2_grpc import ClusterServiceStub
from yandex.cloud.mdb.clickhouse.v1.cluster_service_pb2 import StreamClusterLogsRequest
token = os.getenv("YC_OAUTH_TOKEN")
sdk = yandexcloud.SDK(token=token)
service = sdk.client(ClusterServiceStub)
response = service.streamLogs()
print(response)
StreamClusterLogsRequest
ServiceType
SERVICE_TYPE_UNSPECIFIED
MYSQL_ERROR
MySQL error log.
MYSQL_GENERAL
MySQL general query log.
MYSQL_SLOW_QUERY
MySQL slow query log.
MYSQL_AUDIT
MySQL audit log.
clusterId
: string
ID of the cluster to stream logs for.
To get this ID, make a ClusterService.List request.
columnFilter
: string
Columns from the logs table to request. If no columns are specified, complete log records are returned.
serviceType
: ServiceType
The log type.
fromTime
: google.protobuf.Timestamp
Start timestamp for the logs request.
toTime
: google.protobuf.Timestamp
End timestamp for the logs request. If this field is not set, all existing log records beginning from from_time will be returned first, and then the new records will be returned as they appear.
In essence it has tail -f
command semantics.
recordToken
: string
Record token that can be used to control logs streaming.
Set record_token to the StreamLogRecord.next_record_token, returned by the previous ClusterService.StreamLogs request to start streaming from the next log record.
filter
: string
A filter expression that selects clusters logs listed in the response.
The expression must specify:
- The field name. Currently filtering can be applied to the LogRecord.logs.hostname field.
- An
=
operator. - The value in double quotes (
"
). Must be 3-63 characters long and match the regular expression[a-z][-a-z0-9]{1,61}[a-z0-9]
. Examples of a filter:message.hostname='node1.db.cloud.yandex.net'
StreamLogRecord
A single log record in the logs stream.
record
: LogRecord
One of the requested log records.
nextRecordToken
: string
The token that can be used to continue streaming logs starting from the exact same record. To continue streaming, specify value of next_record_token as the StreamClusterLogsRequest.record_token value in the next ClusterService.StreamLogs request.
This value is interchangeable with ListClusterLogsResponse.next_page_token from ClusterService.ListLogs method.
LogRecord
A single log record.
timestamp
: google.protobuf.Timestamp
Timestamp of the log record.
message
: string
Contents of the log record.