Logger
Define API Loggers.
class google.cloud.logging.logger.Batch(logger, client, resource=None)
Bases: object
Context manager: collect entries to log via a single API call.
Helper returned by Logger.batch()
Parameters
logger (
google.cloud.logging.logger.Logger
) – the logger to which entries will be logged.client (
google.cloud.logging.client.Client
) – The client to use.resource (
Resource
) – (Optional) Monitored resource of the batch, defaults to None, which requires that every entry should have a resource specified. Since the methods used to write entries default the entry’s resource to the global resource type, this parameter is only required if explicitly set to None. If no entries’ resource are set to None, this parameter will be ignored on the server.
commit(client=None)
Send saved log entries as a single API call.
Parameters
client (
Client
orNoneType
) – the client to use. If not passed, falls back to theclient
stored on the current batch.
log_empty(**kw)
Add a entry without payload to be logged during commit()
.
log_proto(message, **kw)
Add a protobuf entry to be logged during commit()
.
Parameters
log_struct(info, **kw)
Add a struct entry to be logged during commit()
.
Parameters
log_text(text, **kw)
Add a text entry to be logged during commit()
.
Parameters
class google.cloud.logging.logger.Logger(name, client, labels=None)
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)
Return a batch to use as a context manager.
Parameters
client (
Client
orNoneType
) – the client to use. If not passed, falls back to theclient
stored on the current topic.Return type
Batch
Returns
A batch to use as a context manager.
property client()
Clent bound to the logger.
delete(client=None)
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
orNoneType
) – the client to use. If not passed, falls back to theclient
stored on the current logger.
property full_name()
Fully-qualified name used in logging APIs
list_entries(projects=None, filter_=None, order_by=None, page_size=None, page_token=None)
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
orDESCENDING
.page_size (int) – Optional. The maximum number of entries in each page of results from this request. Non-positive values are ignored. Defaults to a sensible value set by the API.
page_token (str) – Optional. If present, return the next batch of entries, using the value, which must correspond to the
nextPageToken
value returned in the previous response. Deprecated: use thepages
property of the returned iterator instead of manually passing the token.
Return type
Returns
Iterator of log entries accessible to the current logger. See
LogEntry
.
log_empty(client=None, **kw)
API call: log an empty message via a POST request
See https://cloud.google.com/logging/docs/reference/v2/rest/v2/entries/write
Parameters
log_proto(message, client=None, **kw)
API call: log a protobuf message via a POST request
See https://cloud.google.com/logging/docs/reference/v2/rest/v2/entries/list
Parameters
log_struct(info, client=None, **kw)
API call: log a structured message via a POST request
See https://cloud.google.com/logging/docs/reference/v2/rest/v2/entries/write
Parameters
log_text(text, client=None, **kw)
API call: log a text message via a POST request
See https://cloud.google.com/logging/docs/reference/v2/rest/v2/entries/write
Parameters
property path()
URI path for use in logging APIs
property project()
Project bound to the logger.