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, timestamp=None)[source]#

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

Parameters:
  • message (protobuf message) – the protobuf entry
  • labels (dict) – (optional) mapping of labels for the entry.
  • insert_id (str) – (optional) unique ID for log entry.
  • 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 of event being logged.
log_struct(info, labels=None, insert_id=None, severity=None, http_request=None, timestamp=None)[source]#

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

Parameters:
  • info (dict) – the struct entry
  • labels (dict) – (optional) mapping of labels for the entry.
  • insert_id (str) – (optional) unique ID for log entry.
  • 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 of event being logged.
log_text(text, labels=None, insert_id=None, severity=None, http_request=None, timestamp=None)[source]#

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

Parameters:
  • text (str) – the text entry
  • labels (dict) – (optional) mapping of labels for the entry.
  • insert_id (str) – (optional) unique ID for log entry.
  • 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 of event being logged.
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/reference/v2/rest/v2/projects.logs

Parameters:
  • name (str) – 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) – (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/reference/v2/rest/v2/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/reference/v2/rest/v2/entries/list

Parameters:
  • projects (list of strings) – project IDs to include. If not passed, defaults to the project bound to the client.
  • filter (str) – a filter expression. See: https://cloud.google.com/logging/docs/view/advanced_filters
  • order_by (str) – 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 (str) – opaque marker for the next “page” of entries. If not passed, the API will return the first page of entries.
Return type:

Iterator

Returns:

Iterator of _BaseEntry accessible to the current logger.

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

API call: log a protobuf message via a POST request

See: https://cloud.google.com/logging/docs/reference/v2/rest/v2/entries/list

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) – (optional) mapping of labels for the entry.
  • insert_id (str) – (optional) unique ID for log entry.
  • 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 of event being logged.
log_struct(info, client=None, labels=None, insert_id=None, severity=None, http_request=None, timestamp=None)[source]#

API call: log a structured message via a POST request

See: https://cloud.google.com/logging/docs/reference/v2/rest/v2/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) – (optional) mapping of labels for the entry.
  • insert_id (str) – (optional) unique ID for log entry.
  • 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 of event being logged.
log_text(text, client=None, labels=None, insert_id=None, severity=None, http_request=None, timestamp=None)[source]#

API call: log a text message via a POST request

See: https://cloud.google.com/logging/docs/reference/v2/rest/v2/entries/write

Parameters:
  • text (str) – 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) – (optional) mapping of labels for the entry.
  • insert_id (str) – (optional) unique ID for log entry.
  • 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 of event being logged.
path#

URI path for use in logging APIs

project#

Project bound to the logger.