On January 1, 2020 this library will no longer support Python 2 on the latest released version. Previously released library versions will continue to be available. For more information please visit Python 2 support on Google Cloud.

Entries

Log entries within the Google Stackdriver Logging API.

class google.cloud.logging.entries.LogEntry[source]

Bases: google.cloud.logging.entries.LogEntry

Log entry.

Parameters
  • log_name (str) – the name of the logger used to post the entry.

  • labels (dict) – (optional) mapping of labels for the entry

  • insert_id (text) – (optional) the ID used to identify an entry uniquely.

  • severity (str) – (optional) severity of event being logged.

  • http_request (dict) – (optional) info about HTTP request associated with the entry.

  • timestamp (datetime.datetime) – (optional) timestamp for the entry

  • resource (Resource) – (Optional) Monitored resource of the entry

  • trace (str) – (optional) traceid to apply to the entry.

  • span_id (str) – (optional) span_id within the trace for the log entry. Specify the trace parameter if span_id is set.

  • trace_sampled (bool) – (optional) the sampling decision of the trace associated with the log entry.

  • source_location (dict) – (optional) location in source code from which the entry was emitted.

  • operation (dict) – (optional) additional information about a potentially long-running operation associated with the log entry.

  • logger (google.cloud.logging.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)[source]

Factory: construct an entry given its API representation

Parameters
  • resource (dict) – text entry resource representation returned from the API

  • client (google.cloud.logging.client.Client) – Client which holds credentials and project configuration.

  • loggers (dict) – (Optional) A mapping of logger fullnames -> loggers. If not passed, the entry will have a newly-created logger.

Return type

google.cloud.logging.entries.LogEntry

Returns

Log entry parsed from resource.

to_api_repr()[source]

API repr (JSON format) for entry.

class google.cloud.logging.entries.ProtobufEntry[source]

Bases: google.cloud.logging.entries.LogEntry

Log entry with protobuf message payload.

Parameters
  • log_name (str) – the name of the logger used to post the entry.

  • labels (dict) – (optional) mapping of labels for the entry

  • insert_id (text) – (optional) the ID used to identify an entry uniquely.

  • severity (str) – (optional) severity of event being logged.

  • http_request (dict) – (optional) info about HTTP request associated with the entry.

  • timestamp (datetime.datetime) – (optional) timestamp for the entry

  • resource (Resource) – (Optional) Monitored resource of the entry

  • trace (str) – (optional) traceid to apply to the entry.

  • span_id (str) – (optional) span_id within the trace for the log entry. Specify the trace parameter if span_id is set.

  • trace_sampled (bool) – (optional) the sampling decision of the trace associated with the log entry.

  • source_location (dict) – (optional) location in source code from which the entry was emitted.

  • operation (dict) – (optional) additional information about a potentially long-running operation associated with the log entry.

  • logger (google.cloud.logging.logger.Logger) – the logger used to write the entry.

  • payload (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)[source]

Parse payload into a protobuf message.

Mutates the passed-in message in place.

Parameters

message (Protobuf message) – the message to be logged

to_api_repr()[source]

API repr (JSON format) for entry.

class google.cloud.logging.entries.StructEntry[source]

Bases: google.cloud.logging.entries.LogEntry

Log entry with JSON payload.

Parameters
  • log_name (str) – the name of the logger used to post the entry.

  • labels (dict) – (optional) mapping of labels for the entry

  • insert_id (text) – (optional) the ID used to identify an entry uniquely.

  • severity (str) – (optional) severity of event being logged.

  • http_request (dict) – (optional) info about HTTP request associated with the entry.

  • timestamp (datetime.datetime) – (optional) timestamp for the entry

  • resource (Resource) – (Optional) Monitored resource of the entry

  • trace (str) – (optional) traceid to apply to the entry.

  • span_id (str) – (optional) span_id within the trace for the log entry. Specify the trace parameter if span_id is set.

  • trace_sampled (bool) – (optional) the sampling decision of the trace associated with the log entry.

  • source_location (dict) – (optional) location in source code from which the entry was emitted.

  • operation (dict) – (optional) additional information about a potentially long-running operation associated with the log entry.

  • logger (google.cloud.logging.logger.Logger) – the logger used to write the entry.

  • payload (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()[source]

API repr (JSON format) for entry.

class google.cloud.logging.entries.TextEntry[source]

Bases: google.cloud.logging.entries.LogEntry

Log entry with text payload.

Parameters
  • log_name (str) – the name of the logger used to post the entry.

  • labels (dict) – (optional) mapping of labels for the entry

  • insert_id (text) – (optional) the ID used to identify an entry uniquely.

  • severity (str) – (optional) severity of event being logged.

  • http_request (dict) – (optional) info about HTTP request associated with the entry.

  • timestamp (datetime.datetime) – (optional) timestamp for the entry

  • resource (Resource) – (Optional) Monitored resource of the entry

  • trace (str) – (optional) traceid to apply to the entry.

  • span_id (str) – (optional) span_id within the trace for the log entry. Specify the trace parameter if span_id is set.

  • trace_sampled (bool) – (optional) the sampling decision of the trace associated with the log entry.

  • source_location (dict) – (optional) location in source code from which the entry was emitted.

  • operation (dict) – (optional) additional information about a potentially long-running operation associated with the log entry.

  • logger (google.cloud.logging.logger.Logger) – the logger used to write the entry.

  • payload (str | unicode) – 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()[source]

API repr (JSON format) for entry.

google.cloud.logging.entries.logger_name_from_path(path)[source]

Validate a logger URI path and get the logger name.

Parameters

path (str) – URI path for a logger API request.

Return type

str

Returns

Logger name parsed from path.

Raises

ValueError if the path is ill-formed or if the project from the path does not agree with the project passed in.