Logger
Define API Loggers.
class google.cloud.logging_v2.logger.Logger(name, client, *, labels=None, resource=Resource(type='global', labels={}))
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 (Client) – A client which holds credentials and project configuration for the logger (which requires a project).
resource (Resource) – a monitored resource object representing the resource the code was run on.
labels (Optional[dict]) – Mapping of default labels for entries written via this logger.
batch(*, client=None)
Return a batch to use as a context manager.
Parameters
client (Union[None, *[Client](client.md#google.cloud.logging_v2.client.Client)]*) – The client to use. If not passed, falls back to the
client
stored on the current sink.Returns
A batch to use as a context manager.
Return type
Batch
property client()
Clent bound to the logger.
delete(logger_name=None, *, client=None)
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
logger_name (Optional[str]) – The resource name of the log to delete:
"projects/[PROJECT_ID]/logs/[LOG_ID]" "organizations/[ORGANIZATION_ID]/logs/[LOG_ID]" "billingAccounts/[BILLING_ACCOUNT_ID]/logs/[LOG_ID]" "folders/[FOLDER_ID]/logs/[LOG_ID]"
[LOG_ID]
must be URL-encoded. For example,"projects/my-project-id/logs/syslog"
,"organizations/1234567890/logs/cloudresourcemanager.googleapis.com%2Factivity"
. If not passed, defaults to the project bound to the client.client (Optional[Client]) – The client to use. If not passed, falls back to the
client
stored on the current logger.
property full_name()
Fully-qualified name used in logging APIs
list_entries(*, resource_names=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
resource_names (Optional[Sequence[str]]) – Names of one or more parent resources from which to retrieve log entries:
"projects/[PROJECT_ID]" "organizations/[ORGANIZATION_ID]" "billingAccounts/[BILLING_ACCOUNT_ID]" "folders/[FOLDER_ID]"
If not passed, defaults to the project bound to the client.
filter (Optional[str]) – a filter expression. See https://cloud.google.com/logging/docs/view/advanced_filters By default, a 24 hour filter is applied.
order_by (Optional[str]) – One of
ASCENDING
orDESCENDING
.page_size (Optional[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 (Optional[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.
Returns
Iterator[~logging_v2.entries.LogEntry]
log_empty(*, client=None, **kw)
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)
Log a protobuf message via a POST request
See https://cloud.google.com/logging/docs/reference/v2/rest/v2/entries/list
Parameters
message (google.protobuf.message.Message) – The protobuf message to be logged.
client (Optional[Client]) – The client to use. If not passed, falls back to the
client
stored on the current sink.kw (Optional[dict]) – additional keyword arguments for the entry. See
LogEntry
.
log_struct(info, *, client=None, **kw)
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)
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.