Class Entry (11.2.0)

Package

@google-cloud/logging

Example

const{Logging}=require('@google-cloud/logging');constlogging=newLogging();constsyslog=logging.log('syslog');constmetadata={resource:{type:'gce_instance',labels:{zone:'global',instance_id:'3'}}};constentry=syslog.entry(metadata,{delegate:'my_username'});syslog.alert(entry,(err,apiResponse)=>{if(!err){// Log entry inserted successfully.}});//-// You will also receive `Entry` objects when using// Logging#getEntries() and Log#getEntries().//-logging.getEntries((err,entries)=>{if(!err){// entries[0].data = The data value from the log entry.}});

Constructors

(constructor)(metadata, data)

constructor(metadata?:LogEntry,data?:Data);

Constructs a new instance of theEntry class

Parameters
NameDescription
metadataLogEntry
dataData

Properties

data

data:Data;

metadata

metadata:LogEntry;

Methods

fromApiResponse_(entry)

staticfromApiResponse_(entry:google.logging.v2.LogEntry):Entry;

Create an Entry object from an API response, such asentries:list.

Parameter
NameDescription
entryLogEntry

An API representation of an entry. See aLogEntry.

Returns
TypeDescription
Entry

{Entry}

toJSON(options, projectId)

toJSON(options?:ToJsonOptions,projectId?:string):EntryJson;

Serialize an entry to the format the API expects. Read more:https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry

Parameters
NameDescription
optionsToJsonOptions

Configuration object.

projectIdstring

GCP Project ID.

Returns
TypeDescription
EntryJson

toStructuredJSON(projectId, useMessageField)

toStructuredJSON(projectId?:string,useMessageField?:boolean):StructuredJson;

Serialize an entry to a standard format for any transports, e.g. agents. Read more:https://cloud.google.com/logging/docs/structured-logging

Parameters
NameDescription
projectIdstring
useMessageFieldboolean
Returns
TypeDescription
StructuredJson

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-10-30 UTC.