Stackdriver Logging Client#
Client for interacting with the Google Stackdriver Logging API.
-
class
google.cloud.logging.client.
Client
(project=None, credentials=None, http=None)[source]# Bases:
google.cloud.client.JSONClient
Client to bundle configuration needed for API requests.
Parameters: - project (str) – the project which the client acts on behalf of. If not passed, falls back to the default inferred from the environment.
- credentials (
oauth2client.client.OAuth2Credentials
orNoneType
) – The OAuth2 Credentials to use for the connection owned by this client. If not passed (and if nohttp
object is passed), falls back to the default inferred from the environment. - http (
httplib2.Http
or class that definesrequest()
.) – An optional HTTP object to make requests. If not passed, anhttp
object is created that is bound to thecredentials
for the current object.
-
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 (str) – a filter expression. See: https://cloud.google.com/logging/docs/view/advanced_filters
- order_by (str) – One of
ASCENDING
orDESCENDING
. - 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: tuple, (list, str)
Returns: list of
google.cloud.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
).
-
list_metrics
(page_size=None, page_token=None)[source]# List metrics for the project associated with this client.
See: https://cloud.google.com/logging/docs/api/ref_v2beta1/rest/v2beta1/projects.metrics/list
Parameters: Return type: tuple, (list, str)
Returns: list of
google.cloud.logging.metric.Metric
, plus a “next page token” string: if not None, indicates that more metrics can be retrieved with another call (pass that value aspage_token
).
-
list_sinks
(page_size=None, page_token=None)[source]# List sinks for the project associated with this client.
See: https://cloud.google.com/logging/docs/api/ref_v2beta1/rest/v2beta1/projects.sinks/list
Parameters: Return type: tuple, (list, str)
Returns: list of
google.cloud.logging.sink.Sink
, plus a “next page token” string: if not None, indicates that more sinks can be retrieved with another call (pass that value aspage_token
).
-
logger
(name)[source]# Creates a logger bound to the current client.
Parameters: name (str) – the name of the logger to be constructed. Return type: google.cloud.logging.logger.Logger
Returns: Logger created with the current client.
-
logging_api
# Helper for logging-related API calls.
See: https://cloud.google.com/logging/docs/api/ref_v2beta1/rest/v2beta1/entries https://cloud.google.com/logging/docs/api/ref_v2beta1/rest/v2beta1/projects.logs
-
metric
(name, filter_=None, description='')[source]# Creates a metric bound to the current client.
Parameters: - name (str) – the name of the metric to be constructed.
- filter (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
Metric.reload()
. - description (str) – the description of the metric to be constructed.
If not passed, the instance should already exist,
to be refreshed via
Metric.reload()
.
Return type: Returns: Metric created with the current client.
-
metrics_api
# Helper for log metric-related API calls.
See: https://cloud.google.com/logging/docs/api/ref_v2beta1/rest/v2beta1/projects.metrics
-
sink
(name, filter_=None, destination=None)[source]# Creates a sink bound to the current client.
Parameters: - name (str) – the name of the sink to be constructed.
- filter (str) – (optional) the advanced logs filter expression
defining the entries exported by the sink. If not
passed, the instance should already exist, to be
refreshed via
Sink.reload()
. - destination (str) – destination URI for the entries exported by
the sink. If not passed, the instance should
already exist, to be refreshed via
Sink.reload()
.
Return type: Returns: Sink created with the current client.
-
sinks_api
# Helper for log sink-related API calls.
See: https://cloud.google.com/logging/docs/api/ref_v2beta1/rest/v2beta1/projects.sinks
Connection#
Create / interact with Stackdriver Logging connections.
-
class
google.cloud.logging.connection.
Connection
(credentials=None, http=None)[source]# Bases:
google.cloud.connection.JSONConnection
A connection to Google Stackdriver Logging via the JSON REST API.
Parameters: - credentials (
oauth2client.client.OAuth2Credentials
) – (Optional) The OAuth2 Credentials to use for this connection. - http (
httplib2.Http
or class that definesrequest()
.) – (Optional) HTTP object to make requests. - api_base_url (string) – The base of the API call URL. Defaults to the value
Connection.API_BASE_URL
.
-
API_BASE_URL
= 'https://logging.googleapis.com'# The base of the API call URL.
-
API_URL_TEMPLATE
= '{api_base_url}/{api_version}{path}'# A template for the URL of a particular API call.
-
API_VERSION
= 'v2beta1'# The version of the API, used in building the API call’s URL.
-
SCOPE
= ('https://www.googleapis.com/auth/logging.read', 'https://www.googleapis.com/auth/logging.write', 'https://www.googleapis.com/auth/logging.admin', 'https://www.googleapis.com/auth/cloud-platform')# The scopes required for authenticating as a Logging consumer.
- credentials (