Class Client (3.12.1) Stay organized with collections Save and categorize content based on your preferences.
Client(*,project=None,credentials=None,_http=None,_use_grpc=None,client_info=None,client_options=None)Client to bundle configuration needed for API requests.
Properties
logging_api
Helper for logging-related API calls.
Seehttps://cloud.google.com/logging/docs/reference/v2/rest/v2/entrieshttps://cloud.google.com/logging/docs/reference/v2/rest/v2/projects.logs
metrics_api
Helper for log metric-related API calls.
Seehttps://cloud.google.com/logging/docs/reference/v2/rest/v2/projects.metrics
sinks_api
Helper for log sink-related API calls.
Seehttps://cloud.google.com/logging/docs/reference/v2/rest/v2/projects.sinks
Methods
Client
Client(*,project=None,credentials=None,_http=None,_use_grpc=None,client_info=None,client_options=None)| Parameters | |
|---|---|
| Name | Description |
project | Optional[str]the project which the client acts on behalf of. If not passed, falls back to the default inferred from the environment. |
credentials | Optional[google.auth.credentials.Credentials]Thehe OAuth2 Credentials to use for this client. If not passed (and if no |
_http | Optional[requests.Session]HTTP object to make requests. Can be any object that defines |
_use_grpc | Optional[bool]Explicitly specifies whether to use the gRPC transport or HTTP. If unset, falls back to the |
client_info | Optional[Union[google.api_core.client_info.ClientInfo, google.api_core.gapic_v1.client_info.ClientInfo]]The client info used to send a user-agent string along with API requests. If |
client_options | Optional[Union[dict, google.api_core.client_options.ClientOptions]]Client options used to set user options on the client. API Endpoint should be set through client_options. |
close
close()Closes the Client and all handlers associated with this Client.
flush_handlers
flush_handlers()Flushes all Python log handlers associated with this Client.
get_default_handler
get_default_handler(**kw)Return the default logging handler based on the local environment.
| Parameter | |
|---|---|
| Name | Description |
kw | dictkeyword args passed to handler constructor |
| Returns | |
|---|---|
| Type | Description |
logging.Handler | The default log handler based on the environment |
list_entries
list_entries(*,resource_names=None,filter_=None,order_by=None,max_results=None,page_size=None,page_token=None)Return a generator of log entry resources.
| Parameters | |
|---|---|
| Name | Description |
resource_names | 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 API's client. |
filter_ | stra filter expression. Seehttps://cloud.google.com/logging/docs/view/advanced_filters |
order_by | stror :data: |
max_results | Optional[int]Optional. The maximum number of entries to return. Non-positive values are treated as 0. If None, uses API defaults. |
page_size | intnumber of entries to fetch in each API call. Although requests are paged internally, logs are returned by the generator one at a time. If not passed, defaults to a value set by the API. |
page_token | stropaque marker for the starting "page" of entries. If not passed, the API will return the first page of entries. |
list_metrics
list_metrics(*,max_results=None,page_size=None,page_token=None)List metrics for the project associated with this client.
Seehttps://cloud.google.com/logging/docs/reference/v2/rest/v2/projects.metrics/list
| Parameters | |
|---|---|
| Name | Description |
max_results | Optional[int]Optional. The maximum number of entries to return. Non-positive values are treated as 0. If None, uses API defaults. |
page_size | intnumber of entries to fetch in each API call. Although requests are paged internally, logs are returned by the generator one at a time. If not passed, defaults to a value set by the API. |
page_token | stropaque marker for the starting "page" of entries. If not passed, the API will return the first page of entries. |
list_sinks
list_sinks(*,parent=None,max_results=None,page_size=None,page_token=None)List sinks for the a parent resource.
Seehttps://cloud.google.com/logging/docs/reference/v2/rest/v2/projects.sinks/list
| Parameters | |
|---|---|
| Name | Description |
parent | Optional[str]The parent resource whose sinks are to be listed: :: "projects/[PROJECT_ID]" "organizations/[ORGANIZATION_ID]" "billingAccounts/[BILLING_ACCOUNT_ID]" "folders/[FOLDER_ID]". If not passed, defaults to the project bound to the API's client. |
max_results | Optional[int]Optional. The maximum number of entries to return. Non-positive values are treated as 0. If None, uses API defaults. |
page_size | intnumber of entries to fetch in each API call. Although requests are paged internally, logs are returned by the generator one at a time. If not passed, defaults to a value set by the API. |
page_token | stropaque marker for the starting "page" of entries. If not passed, the API will return the first page of entries. |
logger
logger(name,*,labels=None,resource=None)Creates a logger bound to the current client.
| Parameters | |
|---|---|
| Name | Description |
name | strThe name of the logger to be constructed. |
resource | Optional[a monitored resource object representing the resource the code was run on. If not given, will be inferred from the environment. |
labels | Optional[dict]Mapping of default labels for entries written via this logger. |
| Returns | |
|---|---|
| Type | Description |
| Logger created with the current client. |
metric
metric(name,*,filter_=None,description="")Creates a metric bound to the current client.
| Parameters | |
|---|---|
| Name | Description |
name | strThe name of the metric to be constructed. |
filter_ | Optional[str]The advanced logs filter expression defining the entries tracked by the metric. If not passed, the instance should already exist, to be refreshed via |
description | Optional[str]The description of the metric to be constructed. If not passed, the instance should already exist, to be refreshed via |
| Returns | |
|---|---|
| Type | Description |
| Metric created with the current client. |
setup_logging
setup_logging(*,log_level=20,excluded_loggers=("google.api_core.bidi","werkzeug"),**kw)Attach default Cloud Logging handler to the root logger.
This method uses the default log handler, obtained byget_default_handler, and attaches it to the root Pythonlogger, so that a call such aslogging.warn, as well as all childloggers, will report to Cloud Logging.
| Parameters | |
|---|---|
| Name | Description |
log_level | Optional[int]The logging level threshold of the attached logger, as set by the |
excluded_loggers | Optional[Tuple[str]]The loggers to not attach the handler to. This will always include the loggers in the path of the logging client itself. |
| Returns | |
|---|---|
| Type | Description |
dict | keyword args passed to handler constructor |
sink
sink(name,*,filter_=None,destination=None)Creates a sink bound to the current client.
| Parameters | |
|---|---|
| Name | Description |
name | strthe name of the sink to be constructed. |
filter_ | Optional[str]the advanced logs filter expression defining the entries exported by the sink. If not passed, the instance should already exist, to be refreshed via |
destination | strdestination URI for the entries exported by the sink. If not passed, the instance should already exist, to be refreshed via |
| Returns | |
|---|---|
| Type | Description |
| Sink created with the current client. |
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-10-30 UTC.