Package com.google.cloud.logging
Class LogEntry
- java.lang.Object
-
- com.google.cloud.logging.LogEntry
-
- All Implemented Interfaces:
Serializable
public class LogEntry extends Object implements Serializable
A Cloud Logging log entry. All log entries are represented via objects of this class. Log entries can have different type of payloads: an UTF-8 string (seePayload.StringPayload), a JSON object (seePayload.JsonPayload, or a protobuf object (seePayload.ProtoPayload). Entries can also store additional information about the operation or the HTTP request that generated the log (seegetOperation()andgetHttpRequest(), respectively).- See Also:
- Log Entries and Logs, Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classLogEntry.BuilderA builder forLogEntryobjects.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description booleanequals(Object obj)LogDestinationNamegetDestination()Returns the log path destination name type associated with log entry.HttpRequestgetHttpRequest()Returns information about the HTTP request associated with this log entry, if applicable.StringgetInsertId()Returns a unique ID for the log entry.InstantgetInstantReceiveTimestamp()Returns the time the log entry was received by Cloud Logging, in milliseconds.InstantgetInstantTimestamp()Returns the time at which the event described by the log entry occurred.Map<String,String>getLabels()Returns an optional set of user-defined (key, value) data that provides additional information about the log entry.StringgetLogName()Returns the name of the log to which this log entry belongs.OperationgetOperation()Returns information about an operation associated with the log entry, if applicable.<T extends Payload<?>>
TgetPayload()Returns the payload for this log entry.LonggetReceiveTimestamp()Deprecated.This method is no longer recommended to get the received time timestamp.com.google.cloud.MonitoredResourcegetResource()Returns the monitored resource associated with this log entry.SeveritygetSeverity()Returns the severity of the log entry.SourceLocationgetSourceLocation()Returns the source code location information associated with the log entry, if any.StringgetSpanId()Returns the ID of the trace span associated with the log entry, if any.LonggetTimestamp()Deprecated.This method is no longer recommended to get the entry timestamp.StringgetTrace()Returns the resource name of the trace associated with the log entry, if any.booleangetTraceSampled()Returns the sampling decision of the trace span associated with the log entry, orfalseif there is no trace span.inthashCode()static LogEntry.BuildernewBuilder(Payload<?> payload)Returns a builder forLogEntryobjects given the entry payload.static LogEntryof(Payload<?> payload)Creates aLogEntryobject given the entry payload.static LogEntryof(String logName, com.google.cloud.MonitoredResource resource, Payload<?> payload)Creates aLogEntryobject given the log name, the monitored resource and the entry payload.LogEntry.BuildertoBuilder()Returns aBuilderfor this log entry.StringtoString()StringtoStructuredJsonString()Serializes the object to a one line JSON string in the simplified format that can be parsed by the logging agents that run on Google Cloud resources.
-
-
-
Method Detail
-
getLogName
public String getLogName()
Returns the name of the log to which this log entry belongs. The log name must be less than 512 characters long and can only include the following characters: upper and lower case alphanumeric characters:[A-Za-z0-9]; and punctuation characters:_-./. The forward-slash (/) characters in the log name must be URL-encoded. Examples:syslog,library.googleapis.com%2Fbook_log.
-
getResource
public com.google.cloud.MonitoredResource getResource()
Returns the monitored resource associated with this log entry. Example: a log entry that reports a database error would be associated with the monitored resource designating the particular database that reported the error.
-
getTimestamp
@Deprecated public Long getTimestamp()
Deprecated.This method is no longer recommended to get the entry timestamp.Use
getInstantTimestamp()instead.Returns the time at which the event described by the log entry occurred, in milliseconds.- Returns:
- timestamp in milliseconds
-
getInstantTimestamp
public Instant getInstantTimestamp()
Returns the time at which the event described by the log entry occurred.- Returns:
- timestamp as
Instant
-
getReceiveTimestamp
@Deprecated public Long getReceiveTimestamp()
Deprecated.This method is no longer recommended to get the received time timestamp.Use
getInstantReceiveTimestamp()instead.Returns the time the log entry was received by Cloud Logging, in milliseconds.- Returns:
- timestamp in milliseconds
-
getInstantReceiveTimestamp
public Instant getInstantReceiveTimestamp()
Returns the time the log entry was received by Cloud Logging, in milliseconds.- Returns:
- timestamp as
Instant
-
getSeverity
public Severity getSeverity()
Returns the severity of the log entry. If not set,Severity.DEFAULTis used.
-
getInsertId
public String getInsertId()
Returns a unique ID for the log entry. The Logging service considers other log entries in the same log with the same ID as duplicates which can be removed.
-
getHttpRequest
public HttpRequest getHttpRequest()
Returns information about the HTTP request associated with this log entry, if applicable.
-
getLabels
public Map<String,String> getLabels()
Returns an optional set of user-defined (key, value) data that provides additional information about the log entry.
-
getOperation
public Operation getOperation()
Returns information about an operation associated with the log entry, if applicable.
-
getTrace
public String getTrace()
Returns the resource name of the trace associated with the log entry, if any. If it contains a relative resource name, the name is assumed to be relative to `//tracing.googleapis.com`.
-
getSpanId
public String getSpanId()
Returns the ID of the trace span associated with the log entry, if any.
-
getTraceSampled
public boolean getTraceSampled()
Returns the sampling decision of the trace span associated with the log entry, orfalseif there is no trace span.
-
getSourceLocation
public SourceLocation getSourceLocation()
Returns the source code location information associated with the log entry, if any.
-
getPayload
public <T extends Payload<?>> T getPayload()
Returns the payload for this log entry. The log entry payload can be an UTF-8 string (seePayload.StringPayload), a JSON object (seePayload.JsonPayload, or a protobuf object (seePayload.ProtoPayload).- See Also:
- Log Entries and Logs
-
getDestination
public LogDestinationName getDestination()
Returns the log path destination name type associated with log entry. By default, project name based destination is used.- See Also:
- logName
-
toBuilder
public LogEntry.Builder toBuilder()
Returns aBuilderfor this log entry.
-
toStructuredJsonString
public String toStructuredJsonString()
Serializes the object to a one line JSON string in the simplified format that can be parsed by the logging agents that run on Google Cloud resources.
-
newBuilder
public static LogEntry.Builder newBuilder(Payload<?> payload)
Returns a builder forLogEntryobjects given the entry payload.
-
of
public static LogEntry of(Payload<?> payload)
Creates aLogEntryobject given the entry payload.
-
-