# Class LogEntry (3.34.0)

3.34.0 (latest) 3.32.0 3.29.0 3.28.0 3.26.0 3.24.0 3.23.10 3.22.6 3.21.4 3.20.7 3.19.0 3.18.0 3.17.2 3.16.2 3.15.17 3.14.9 3.13.7 3.12.1 3.11.10 3.10.7 3.9.0 3.8.0 3.7.6 3.6.4 3.5.3

    public class LogEntry 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 (see [Payload.StringPayload](https://docs.cloud.google.com/java/docs/reference/google-cloud-logging/latest/com.google.cloud.logging.Payload.StringPayload)), a JSON
object (see [Payload.JsonPayload](https://docs.cloud.google.com/java/docs/reference/google-cloud-logging/latest/com.google.cloud.logging.Payload.JsonPayload), or a protobuf object (see [Payload.ProtoPayload](https://docs.cloud.google.com/java/docs/reference/google-cloud-logging/latest/com.google.cloud.logging.Payload.ProtoPayload)).
Entries can also store additional information about the operation or the HTTP request that
generated the log (see [LogEntry#getOperation()](https://docs.cloud.google.com/java/docs/reference/google-cloud-logging/latest/com.google.cloud.logging.LogEntry#com_google_cloud_logging_LogEntry_getOperation__) and [LogEntry#getHttpRequest()](https://docs.cloud.google.com/java/docs/reference/google-cloud-logging/latest/com.google.cloud.logging.LogEntry#com_google_cloud_logging_LogEntry_getHttpRequest__),
respectively).
See Also: [Log Entries and Logs](https://cloud.google.com/logging/docs/view/logs_index)

## Inheritance

[Object](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html) \> LogEntry

## Implements

[Serializable](https://docs.oracle.com/javase/8/docs/api/java/io/Serializable.html)

## Inherited Members

[Object.clone()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#clone--) [Object.equals(Object)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#equals-java.lang.Object-) [Object.finalize()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#finalize--) [Object.getClass()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#getClass--) [Object.hashCode()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#hashCode--) [Object.notify()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notify--) [Object.notifyAll()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notifyAll--) [Object.toString()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#toString--) [Object.wait()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait--) [Object.wait(long)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-) [Object.wait(long,int)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-int-)

## Static Methods

### fromPb(LogEntry entryPb)

    public static LogEntry fromPb(LogEntry entryPb)

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `entryPb` | `https://docs.cloud.google.com/java/docs/reference/google-cloud-logging/latest/com.google.logging.v2.LogEntry` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-logging/latest/com.google.cloud.logging.LogEntry` |   |

### newBuilder(Payload\<?\> payload)

    public static LogEntry.Builder newBuilder(Payload<?> payload)

Returns a builder for `LogEntry` objects given the entry payload.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `payload` | `https://docs.cloud.google.com/java/docs/reference/google-cloud-logging/latest/com.google.cloud.logging.Payload<?>` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-logging/latest/com.google.cloud.logging.LogEntry.Builder` |   |

### of(Payload\<?\> payload)

    public static LogEntry of(Payload<?> payload)

Creates a `LogEntry` object given the entry payload.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `payload` | `https://docs.cloud.google.com/java/docs/reference/google-cloud-logging/latest/com.google.cloud.logging.Payload<?>` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-logging/latest/com.google.cloud.logging.LogEntry` |   |

### of(String logName, MonitoredResource resource, Payload\<?\> payload)

    public static LogEntry of(String logName, MonitoredResource resource, Payload<?> payload)

Creates a `LogEntry` object given the log name, the monitored resource and the entry
payload.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `logName` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |
| `resource` | `com.google.cloud.MonitoredResource` |
| `payload` | `https://docs.cloud.google.com/java/docs/reference/google-cloud-logging/latest/com.google.cloud.logging.Payload<?>` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-logging/latest/com.google.cloud.logging.LogEntry` |   |

### toPbFunction(String projectId)

    public static Function<LogEntry,LogEntry> toPbFunction(String projectId)

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `projectId` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `com.google.common.base.Function<https://docs.cloud.google.com/java/docs/reference/google-cloud-logging/latest/com.google.cloud.logging.LogEntry,https://docs.cloud.google.com/java/docs/reference/google-cloud-logging/latest/com.google.logging.v2.LogEntry>` |   |

## Methods

### \<T\>getPayload()

    public T <T>getPayload()

Returns the payload for this log entry. The log entry payload can be an UTF-8 string (see
[Payload.StringPayload](https://docs.cloud.google.com/java/docs/reference/google-cloud-logging/latest/com.google.cloud.logging.Payload.StringPayload)), a JSON object (see [Payload.JsonPayload](https://docs.cloud.google.com/java/docs/reference/google-cloud-logging/latest/com.google.cloud.logging.Payload.JsonPayload), or a protobuf
object (see [Payload.ProtoPayload](https://docs.cloud.google.com/java/docs/reference/google-cloud-logging/latest/com.google.cloud.logging.Payload.ProtoPayload)).
See Also: [Log Entries and Logs](https://cloud.google.com/logging/docs/view/logs_index)

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `T` |   |

### equals(Object obj)

    public boolean equals(Object obj)

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `obj` | `https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |   |

**Overrides** [Object.equals(Object)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#equals-java.lang.Object-)

### 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](https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry)

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-logging/latest/com.google.cloud.logging.LogDestinationName` |   |

### getHttpRequest()

    public HttpRequest getHttpRequest()

Returns information about the HTTP request associated with this log entry, if applicable.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-logging/latest/com.google.cloud.logging.HttpRequest` |   |

### 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.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |   |

### getInstantReceiveTimestamp()

    public Instant getInstantReceiveTimestamp()

Returns the time the log entry was received by Cloud Logging, in milliseconds.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/time/Instant.html` | timestamp as [Instant](https://docs.oracle.com/javase/8/docs/api/java/time/Instant.html) |

### getInstantTimestamp()

    public Instant getInstantTimestamp()

Returns the time at which the event described by the log entry occurred.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/time/Instant.html` | timestamp as [Instant](https://docs.oracle.com/javase/8/docs/api/java/time/Instant.html) |

### getLabels()

    public Map<String,String> getLabels()

Returns an optional set of user-defined (key, value) data that provides additional information
about the log entry.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/util/Map.html<https://docs.oracle.com/javase/8/docs/api/java/lang/String.html,https://docs.oracle.com/javase/8/docs/api/java/lang/String.html>` |   |

### 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`.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |   |

### getOperation()

    public Operation getOperation()

Returns information about an operation associated with the log entry, if applicable.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-logging/latest/com.google.cloud.logging.Operation` |   |

### 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** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/lang/Long.html` | timestamp in milliseconds |

### getResource()

    public 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.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `com.google.cloud.MonitoredResource` |   |

### getSeverity()

    public Severity getSeverity()

Returns the severity of the log entry. If not set, [Severity#DEFAULT](https://docs.cloud.google.com/java/docs/reference/google-cloud-logging/latest/com.google.cloud.logging.Severity#com_google_cloud_logging_Severity_DEFAULT) is used.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-logging/latest/com.google.cloud.logging.Severity` |   |

### getSourceLocation()

    public SourceLocation getSourceLocation()

Returns the source code location information associated with the log entry, if any.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-logging/latest/com.google.cloud.logging.SourceLocation` |   |

### getSpanId()

    public String getSpanId()

Returns the ID of the trace span associated with the log entry, if any.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |   |

### 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** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/lang/Long.html` | timestamp in milliseconds |

### 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`.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |   |

### getTraceSampled()

    public boolean getTraceSampled()

Returns the sampling decision of the trace span associated with the log entry, or `false`
if there is no trace span.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |   |

### hashCode()

    public int hashCode()

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |   |

**Overrides** [Object.hashCode()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#hashCode--)

### toBuilder()

    public LogEntry.Builder toBuilder()

Returns a `Builder` for this log entry.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-logging/latest/com.google.cloud.logging.LogEntry.Builder` |   |

### toString()

    public String toString()

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |   |

**Overrides** [Object.toString()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#toString--)

### 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.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |   |