# Log Entries

3.16.0 (latest) 3.15.0 3.13.0 3.12.1 3.11.3 3.10.0 3.9.0 3.8.0 3.7.0 3.6.0 3.5.0 3.4.0 3.3.1 3.2.5 3.1.2 3.0.0 2.7.2 2.6.0 2.5.0 2.4.0 2.3.1 2.2.0 2.1.1 2.0.2 1.15.3 1.14.0 1.13.0 1.12.1 Log entries within the Google Cloud Logging API.

### *class* google.cloud.logging_v2.entries.LogEntry(log_name=None, labels=None, insert_id=None, severity=None, http_request=None, timestamp=None, resource=Resource(type='global', labels={}), trace=None, span_id=None, trace_sampled=None, source_location=None, operation=None, logger=None, payload=None)

Bases: `google.cloud.logging_v2.entries.LogEntry`

Log entry.

- **Parameters**

  - **log_name** ([*str*](https://docs.python.org/3/library/stdtypes.html#str)) -- The name of the logger used to post the entry.

  - **labels** (*Optional* *\[* [*dict*](https://docs.python.org/3/library/stdtypes.html#dict)*\]*) -- Mapping of labels for the entry

  - **insert_id** (*Optional* *\[* [*str*](https://docs.python.org/3/library/stdtypes.html#str)*\]*) -- The ID used to identify an entry
    uniquely.

  - **severity** (*Optional* *\[* [*str*](https://docs.python.org/3/library/stdtypes.html#str)*\]*) -- The severity of the event being logged.

  - **http_request** (*Optional* *\[* [*dict*](https://docs.python.org/3/library/stdtypes.html#dict)*\]*) -- Info about HTTP request associated
    with the entry.

  - **timestamp** (*Optional* *\[* [*datetime.datetime*](https://docs.python.org/3/library/datetime.html#datetime.datetime)*\]*) -- Timestamp for the entry.

  - **resource** (*Optional* *\[* [*google.cloud.logging_v2.resource.Resource*](https://docs.cloud.google.com/python/docs/reference/logging/latest/resource#google.cloud.logging_v2.resource.Resource)*\]*) -- Monitored resource of the entry.

  - **trace** (*Optional* *\[* [*str*](https://docs.python.org/3/library/stdtypes.html#str)*\]*) -- Trace ID to apply to the entry.

  - **span_id** (*Optional* *\[* [*str*](https://docs.python.org/3/library/stdtypes.html#str)*\]* ) -- Span ID within the trace for the log
    entry. Specify the trace parameter if `span_id` is set.

  - **trace_sampled** (*Optional* *\[* [*bool*](https://docs.python.org/3/library/functions.html#bool)*\]*) -- The sampling decision of the trace
    associated with the log entry.

  - **source_location** (*Optional* *\[* [*dict*](https://docs.python.org/3/library/stdtypes.html#dict)*\]*) -- Location in source code from which
    the entry was emitted.

  - **operation** (*Optional* *\[* [*dict*](https://docs.python.org/3/library/stdtypes.html#dict)*\]*) -- Additional information about a potentially
    long-running operation associated with the log entry.

  - **logger** ([*logging_v2.logger.Logger*](https://docs.cloud.google.com/python/docs/reference/logging/latest/logger#google.cloud.logging_v2.logger.Logger)) -- the logger used
    to write the entry.

See:
<https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry>

Create new instance of LogEntry(log_name, labels, insert_id, severity, http_request, timestamp, resource, trace, span_id, trace_sampled, source_location, operation, logger, payload)

#### *classmethod* from_api_repr(resource, client, \*, loggers=None)

Construct an entry given its API representation

- **Parameters**

  - **resource** ([*dict*](https://docs.python.org/3/library/stdtypes.html#dict)) -- text entry resource representation returned from
    the API

  - **client** ([*Client*](https://docs.cloud.google.com/python/docs/reference/logging/latest/client#google.cloud.logging_v2.client.Client)) -- Client which holds credentials and project configuration.

  - **loggers** (*Optional* *\[* [*dict*](https://docs.python.org/3/library/stdtypes.html#dict)*\]*) -- A mapping of logger fullnames -\> loggers. If not
    passed, the entry will have a newly-created logger if possible,
    or an empty logger field if not.

- **Returns**

  Log entry parsed from `resource`.
- **Return type**

  google.cloud.logging.entries.LogEntry

#### to_api_repr()

API repr (JSON format) for entry.

### *class* google.cloud.logging_v2.entries.ProtobufEntry(log_name=None, labels=None, insert_id=None, severity=None, http_request=None, timestamp=None, resource=Resource(type='global', labels={}), trace=None, span_id=None, trace_sampled=None, source_location=None, operation=None, logger=None, payload=None)

Bases: `google.cloud.logging_v2.entries.LogEntry`

Log entry with protobuf message payload.

- **Parameters**

  - **log_name** ([*str*](https://docs.python.org/3/library/stdtypes.html#str)) -- The name of the logger used to post the entry.

  - **labels** (*Optional* *\[* [*dict*](https://docs.python.org/3/library/stdtypes.html#dict)*\]*) -- Mapping of labels for the entry

  - **insert_id** (*Optional* *\[* [*str*](https://docs.python.org/3/library/stdtypes.html#str)*\]*) -- The ID used to identify an entry
    uniquely.

  - **severity** (*Optional* *\[* [*str*](https://docs.python.org/3/library/stdtypes.html#str)*\]*) -- The severity of the event being logged.

  - **http_request** (*Optional* *\[* [*dict*](https://docs.python.org/3/library/stdtypes.html#dict)*\]*) -- Info about HTTP request associated
    with the entry.

  - **timestamp** (*Optional* *\[* [*datetime.datetime*](https://docs.python.org/3/library/datetime.html#datetime.datetime)*\]*) -- Timestamp for the entry.

  - **resource** (*Optional* *\[* [*google.cloud.logging_v2.resource.Resource*](https://docs.cloud.google.com/python/docs/reference/logging/latest/resource#google.cloud.logging_v2.resource.Resource)*\]*) -- Monitored resource of the entry.

  - **trace** (*Optional* *\[* [*str*](https://docs.python.org/3/library/stdtypes.html#str)*\]*) -- Trace ID to apply to the entry.

  - **span_id** (*Optional* *\[* [*str*](https://docs.python.org/3/library/stdtypes.html#str)*\]* ) -- Span ID within the trace for the log
    entry. Specify the trace parameter if `span_id` is set.

  - **trace_sampled** (*Optional* *\[* [*bool*](https://docs.python.org/3/library/functions.html#bool)*\]*) -- The sampling decision of the trace
    associated with the log entry.

  - **source_location** (*Optional* *\[* [*dict*](https://docs.python.org/3/library/stdtypes.html#dict)*\]*) -- Location in source code from which
    the entry was emitted.

  - **operation** (*Optional* *\[* [*dict*](https://docs.python.org/3/library/stdtypes.html#dict)*\]*) -- Additional information about a potentially
    long-running operation associated with the log entry.

  - **logger** ([*logging_v2.logger.Logger*](https://docs.cloud.google.com/python/docs/reference/logging/latest/logger#google.cloud.logging_v2.logger.Logger)) -- the logger used
    to write the entry.

  - **payload** (*google.protobuf.Message*) -- payload for the log entry.

See:
<https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry>

Create new instance of LogEntry(log_name, labels, insert_id, severity, http_request, timestamp, resource, trace, span_id, trace_sampled, source_location, operation, logger, payload)

#### parse_message(message)

Parse payload into a protobuf message.

Mutates the passed-in `message` in place.

- **Parameters**

  **message** (*google.protobuf.Message*) -- the message to be logged

#### to_api_repr()

API repr (JSON format) for entry.

### *class* google.cloud.logging_v2.entries.StructEntry(log_name=None, labels=None, insert_id=None, severity=None, http_request=None, timestamp=None, resource=Resource(type='global', labels={}), trace=None, span_id=None, trace_sampled=None, source_location=None, operation=None, logger=None, payload=None)

Bases: `google.cloud.logging_v2.entries.LogEntry`

Log entry with JSON payload.

- **Parameters**

  - **log_name** ([*str*](https://docs.python.org/3/library/stdtypes.html#str)) -- The name of the logger used to post the entry.

  - **labels** (*Optional* *\[* [*dict*](https://docs.python.org/3/library/stdtypes.html#dict)*\]*) -- Mapping of labels for the entry

  - **insert_id** (*Optional* *\[* [*str*](https://docs.python.org/3/library/stdtypes.html#str)*\]*) -- The ID used to identify an entry
    uniquely.

  - **severity** (*Optional* *\[* [*str*](https://docs.python.org/3/library/stdtypes.html#str)*\]*) -- The severity of the event being logged.

  - **http_request** (*Optional* *\[* [*dict*](https://docs.python.org/3/library/stdtypes.html#dict)*\]*) -- Info about HTTP request associated
    with the entry.

  - **timestamp** (*Optional* *\[* [*datetime.datetime*](https://docs.python.org/3/library/datetime.html#datetime.datetime)*\]*) -- Timestamp for the entry.

  - **resource** (*Optional* *\[* [*google.cloud.logging_v2.resource.Resource*](https://docs.cloud.google.com/python/docs/reference/logging/latest/resource#google.cloud.logging_v2.resource.Resource)*\]*) -- Monitored resource of the entry.

  - **trace** (*Optional* *\[* [*str*](https://docs.python.org/3/library/stdtypes.html#str)*\]*) -- Trace ID to apply to the entry.

  - **span_id** (*Optional* *\[* [*str*](https://docs.python.org/3/library/stdtypes.html#str)*\]* ) -- Span ID within the trace for the log
    entry. Specify the trace parameter if `span_id` is set.

  - **trace_sampled** (*Optional* *\[* [*bool*](https://docs.python.org/3/library/functions.html#bool)*\]*) -- The sampling decision of the trace
    associated with the log entry.

  - **source_location** (*Optional* *\[* [*dict*](https://docs.python.org/3/library/stdtypes.html#dict)*\]*) -- Location in source code from which
    the entry was emitted.

  - **operation** (*Optional* *\[* [*dict*](https://docs.python.org/3/library/stdtypes.html#dict)*\]*) -- Additional information about a potentially
    long-running operation associated with the log entry.

  - **logger** ([*logging_v2.logger.Logger*](https://docs.cloud.google.com/python/docs/reference/logging/latest/logger#google.cloud.logging_v2.logger.Logger)) -- the logger used
    to write the entry.

  - **payload** ([*dict*](https://docs.python.org/3/library/stdtypes.html#dict)) -- payload for the log entry.

See:
<https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry>

Create new instance of LogEntry(log_name, labels, insert_id, severity, http_request, timestamp, resource, trace, span_id, trace_sampled, source_location, operation, logger, payload)

#### to_api_repr()

API repr (JSON format) for entry.

### *class* google.cloud.logging_v2.entries.TextEntry(log_name=None, labels=None, insert_id=None, severity=None, http_request=None, timestamp=None, resource=Resource(type='global', labels={}), trace=None, span_id=None, trace_sampled=None, source_location=None, operation=None, logger=None, payload=None)

Bases: `google.cloud.logging_v2.entries.LogEntry`

Log entry with text payload.

- **Parameters**

  - **log_name** ([*str*](https://docs.python.org/3/library/stdtypes.html#str)) -- The name of the logger used to post the entry.

  - **labels** (*Optional* *\[* [*dict*](https://docs.python.org/3/library/stdtypes.html#dict)*\]*) -- Mapping of labels for the entry

  - **insert_id** (*Optional* *\[* [*str*](https://docs.python.org/3/library/stdtypes.html#str)*\]*) -- The ID used to identify an entry
    uniquely.

  - **severity** (*Optional* *\[* [*str*](https://docs.python.org/3/library/stdtypes.html#str)*\]*) -- The severity of the event being logged.

  - **http_request** (*Optional* *\[* [*dict*](https://docs.python.org/3/library/stdtypes.html#dict)*\]*) -- Info about HTTP request associated
    with the entry.

  - **timestamp** (*Optional* *\[* [*datetime.datetime*](https://docs.python.org/3/library/datetime.html#datetime.datetime)*\]*) -- Timestamp for the entry.

  - **resource** (*Optional* *\[* [*google.cloud.logging_v2.resource.Resource*](https://docs.cloud.google.com/python/docs/reference/logging/latest/resource#google.cloud.logging_v2.resource.Resource)*\]*) -- Monitored resource of the entry.

  - **trace** (*Optional* *\[* [*str*](https://docs.python.org/3/library/stdtypes.html#str)*\]*) -- Trace ID to apply to the entry.

  - **span_id** (*Optional* *\[* [*str*](https://docs.python.org/3/library/stdtypes.html#str)*\]* ) -- Span ID within the trace for the log
    entry. Specify the trace parameter if `span_id` is set.

  - **trace_sampled** (*Optional* *\[* [*bool*](https://docs.python.org/3/library/functions.html#bool)*\]*) -- The sampling decision of the trace
    associated with the log entry.

  - **source_location** (*Optional* *\[* [*dict*](https://docs.python.org/3/library/stdtypes.html#dict)*\]*) -- Location in source code from which
    the entry was emitted.

  - **operation** (*Optional* *\[* [*dict*](https://docs.python.org/3/library/stdtypes.html#dict)*\]*) -- Additional information about a potentially
    long-running operation associated with the log entry.

  - **logger** ([*logging_v2.logger.Logger*](https://docs.cloud.google.com/python/docs/reference/logging/latest/logger#google.cloud.logging_v2.logger.Logger)) -- the logger used
    to write the entry.

  - **payload** ([*str*](https://docs.python.org/3/library/stdtypes.html#str)) -- payload for the log entry.

See:
<https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry>

Create new instance of LogEntry(log_name, labels, insert_id, severity, http_request, timestamp, resource, trace, span_id, trace_sampled, source_location, operation, logger, payload)

#### to_api_repr()

API repr (JSON format) for entry.

### google.cloud.logging_v2.entries.logger_name_from_path(path, project=None)

Validate a logger URI path and get the logger name.

- **Parameters**

  - **path** ([*str*](https://docs.python.org/3/library/stdtypes.html#str)) -- URI path for a logger API request

  - **project** ([*str*](https://docs.python.org/3/library/stdtypes.html#str)) -- The project the path is expected to belong to

- **Returns**

  Logger name parsed from `path`.
- **Return type**

  [str](https://docs.python.org/3/library/stdtypes.html#str)
- **Raises**

  [**ValueError**](https://docs.python.org/3/library/exceptions.html#ValueError) -- If the `path` is ill-formed of if the project
  from `path` does not agree with the `project` passed in.