Skip to main content

Write

Write log entries to specified destination.

import { cloudApi, serviceClients, Session } from "@yandex-cloud/nodejs-sdk";

const LogLevel_Level = cloudApi.logging.log_entry.LogLevel_Level;
const WriteRequest = cloudApi.logging.log_ingestion_service.WriteRequest;

(async () => {
const authToken = process.env["YC_OAUTH_TOKEN"];
const session = new Session({ oauthToken: authToken });
const client = session.client(serviceClients.LogIngestionServiceClient);

const result = await client.write(
WriteRequest.fromPartial({
destination: {
// logGroupId: "logGroupId",
// folderId: "folderId"
},
// resource: {
// type: "type",
// id: "id"
// },
// entries: [{
// timestamp: {
// seconds: 0,
// nanos: 0
// },
// level: LogLevel_Level.TRACE,
// message: "message",
// jsonPayload: {},
// streamName: "streamName"
// }],
// defaults: {
// level: LogLevel_Level.TRACE,
// jsonPayload: {},
// streamName: "streamName"
// }
})
);
console.log(result);
})();

WriteRequest​

destination : Destination​

Log entries destination.

See Destination for details.

resource : LogEntryResource​

Common resource (type, ID) specification for log entries.

entries : IncomingLogEntry​

List of log entries.

defaults : LogEntryDefaults​

Log entries defaults.

See LogEntryDefaults for details.

Destination​

One of destination​

Entry destination.

  • logGroupId : string​

    Entry should be written to log group resolved by ID.

  • folderId : string​

    Entry should be written to default log group for the folder.

LogEntryResource​

Log entry resource specification.

May be used either by services and by user.

type : string​

Resource type, i.e., serverless.function

id : string​

Resource ID, i.e., ID of the function producing logs.

IncomingLogEntry​

timestamp : google.protobuf.Timestamp​

Timestamp of the entry.

level : LogLevel.Level​

Entry severity.

See LogLevel.Level for details.

message : string​

Entry text message.

jsonPayload : google.protobuf.Struct​

Entry annotation.

streamName : string​

Entry stream name.

LogEntryDefaults​

level : LogLevel.Level​

Default entry severity. Will be applied if entry level is unspecified.

See LogLevel.Level for details.

jsonPayload : google.protobuf.Struct​

Default entry annotation. Will be merged with entry annotation. Any conflict will be resolved in favor of entry own annotation.

streamName : string​

Entry stream name.

WriteResponse​

errors : google.rpc.Status​

Map<idx, status> of ingest failures.

If entry with idx N is absent, it was ingested successfully.