Logger#

Define API Loggers.

class google.cloud.logging.logger.Batch(logger, client)[source]#

Bases: object

Context manager: collect entries to log via a single API call.

Helper returned by Logger.batch()

Parameters:
commit(client=None)[source]#

Send saved log entries as a single API call.

Parameters:client (Client or NoneType) – the client to use. If not passed, falls back to the client stored on the current batch.
log_proto(message, labels=None, insert_id=None, severity=None, http_request=None)[source]#

Add a protobuf entry to be logged during commit().

Parameters:
  • message (protobuf message) – the protobuf entry
  • labels (dict or NoneType) – (optional) mapping of labels for the entry.
  • insert_id (string or NoneType) – (optional) unique ID for log entry.
  • severity (string or NoneType) – (optional) severity of event being logged.
  • http_request (dict or NoneType) – (optional) info about HTTP request associated with the entry.
log_struct(info, labels=None, insert_id=None, severity=None, http_request=None)[source]#

Add a struct entry to be logged during commit().

Parameters:
  • info (dict) – the struct entry
  • labels (dict or NoneType) – (optional) mapping of labels for the entry.
  • insert_id (string or NoneType) – (optional) unique ID for log entry.
  • severity (string or NoneType) – (optional) severity of event being logged.
  • http_request (dict or NoneType) – (optional) info about HTTP request associated with the entry.
log_text(text, labels=None, insert_id=None, severity=None, http_request=None)[source]#

Add a text entry to be logged during commit().

Parameters:
  • text (string) – the text entry
  • labels (dict or NoneType) – (optional) mapping of labels for the entry.
  • insert_id (string or NoneType) – (optional) unique ID for log entry.
  • severity (string or NoneType) – (optional) severity of event being logged.
  • http_request (dict or NoneType) – (optional) info about HTTP request associated with the entry.
class google.cloud.logging.logger.Logger(name, client, labels=None)[source]#

Bases: object

Loggers represent named targets for log entries.

See: https://cloud.google.com/logging/docs/api/ref_v2beta1/rest/v2beta1/projects.logs

Parameters:
  • name (string) – the name of the logger
  • client (google.cloud.logging.client.Client) – A client which holds credentials and project configuration for the logger (which requires a project).
  • labels (dict or NoneType) – (optional) mapping of default labels for entries written via this logger.
batch(client=None)[source]#

Return a batch to use as a context manager.

Parameters:client (Client or NoneType) – the client to use. If not passed, falls back to the client stored on the current topic.
Return type:Batch
Returns:A batch to use as a context manager.
client#

Clent bound to the logger.

delete(client=None)[source]#

API call: delete all entries in a logger via a DELETE request

See: https://cloud.google.com/logging/docs/api/ref_v2beta1/rest/v2beta1/projects.logs/delete

Parameters:client (Client or NoneType) – the client to use. If not passed, falls back to the client stored on the current logger.
full_name#

Fully-qualified name used in logging APIs

list_entries(projects=None, filter_=None, order_by=None, page_size=None, page_token=None)[source]#

Return a page of log entries.

See: https://cloud.google.com/logging/docs/api/ref_v2beta1/rest/v2beta1/entries/list

Parameters:
  • projects (list of strings) – project IDs to include. If not passed, defaults to the project bound to the client.
  • filter (string) – a filter expression. See: https://cloud.google.com/logging/docs/view/advanced_filters
  • order_by (string) – One of ASCENDING or DESCENDING.
  • page_size (int) – maximum number of entries to return, If not passed, defaults to a value set by the API.
  • page_token (string) – opaque marker for the next “page” of entries. If not passed, the API will return the first page of entries.
Return type:

tuple, (list, str)

Returns:

list of google.cloud.logging.entry.TextEntry, plus a “next page token” string: if not None, indicates that more entries can be retrieved with another call (pass that value as page_token).

log_proto(message, client=None, labels=None, insert_id=None, severity=None, http_request=None)[source]#

API call: log a protobuf message via a POST request

See: https://cloud.google.com/logging/docs/api/ref_v2beta1/rest/v2beta1/entries/write

Parameters:
  • message (Protobuf message) – the message to be logged
  • client (Client or NoneType) – the client to use. If not passed, falls back to the client stored on the current logger.
  • labels (dict or NoneType) – (optional) mapping of labels for the entry.
  • insert_id (string or NoneType) – (optional) unique ID for log entry.
  • severity (string or NoneType) – (optional) severity of event being logged.
  • http_request (dict or NoneType) – (optional) info about HTTP request associated with the entry.
log_struct(info, client=None, labels=None, insert_id=None, severity=None, http_request=None)[source]#

API call: log a structured message via a POST request

See: https://cloud.google.com/logging/docs/api/ref_v2beta1/rest/v2beta1/entries/write

Parameters:
  • info (dict) – the log entry information
  • client (Client or NoneType) – the client to use. If not passed, falls back to the client stored on the current logger.
  • labels (dict or NoneType) – (optional) mapping of labels for the entry.
  • insert_id (string or NoneType) – (optional) unique ID for log entry.
  • severity (string or NoneType) – (optional) severity of event being logged.
  • http_request (dict or NoneType) – (optional) info about HTTP request associated with the entry.
log_text(text, client=None, labels=None, insert_id=None, severity=None, http_request=None)[source]#

API call: log a text message via a POST request

See: https://cloud.google.com/logging/docs/api/ref_v2beta1/rest/v2beta1/entries/write

Parameters:
  • text (text) – the log message.
  • client (Client or NoneType) – the client to use. If not passed, falls back to the client stored on the current logger.
  • labels (dict or NoneType) – (optional) mapping of labels for the entry.
  • insert_id (string or NoneType) – (optional) unique ID for log entry.
  • severity (string or NoneType) – (optional) severity of event being logged.
  • http_request (dict or NoneType) – (optional) info about HTTP request associated with the entry
path#

URI path for use in logging APIs

project#

Project bound to the logger.