Logger#
Define API Loggers.
-
class
gcloud.logging.logger.Batch(logger, client)[source]# Bases:
objectContext manager: collect entries to log via a single API call.
Helper returned by
Logger.batch()Parameters: - logger (
gcloud.logging.logger.Logger) – the logger to which entries will be logged. - client (
gcloud.logging.client.Client) – The client to use.
-
commit(client=None)[source]# Send saved log entries as a single API call.
Parameters: client ( gcloud.logging.client.ClientorNoneType) – the client to use. If not passed, falls back to theclientstored 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.
- logger (
-
class
gcloud.logging.logger.Logger(name, client, labels=None)[source]# Bases:
objectLoggers 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 (
gcloud.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 ( gcloud.logging.client.ClientorNoneType) – the client to use. If not passed, falls back to theclientstored on the current topic.Return type: BatchReturns: 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 ( gcloud.logging.client.ClientorNoneType) – the client to use. If not passed, falls back to theclientstored 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
gcloud.logging.ASCENDINGorgcloud.logging.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
gcloud.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 aspage_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 (
gcloud.logging.client.ClientorNoneType) – the client to use. If not passed, falls back to theclientstored 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 (
gcloud.logging.client.ClientorNoneType) – the client to use. If not passed, falls back to theclientstored 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 (
gcloud.logging.client.ClientorNoneType) – the client to use. If not passed, falls back to theclientstored 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.