google.logging.v2.logging_service_v2_api

Accesses the google.logging.v2 LoggingServiceV2 API.

Classes

LoggingServiceV2Api([service_path, port, ...]) Service for ingesting and querying logs.
class google.logging.v2.logging_service_v2_api.LoggingServiceV2Api(service_path='logging.googleapis.com', port=443, channel=None, metadata_transformer=None, ssl_creds=None, scopes=None, client_config=None, timeout=30, app_name='gax', app_version='0.12.0')[source]

Service for ingesting and querying logs.

Constructor.

Parameters:
  • service_path (string) – The domain name of the API remote host.
  • port (int) – The port on which to connect to the remote host.
  • channel (grpc.beta.implementations.Channel) – A Channel object through which to make calls.
  • ssl_creds (grpc.beta.implementations.ClientCredentials) – A ClientCredentials for use with an SSL-enabled channel.
  • client_config (dict) – A dictionary for call options for each method. See google.gax.construct_settings() for the structure of this data. Falls back to the default config if not specified or the specified config is missing data points.
  • metadata_transformer (Callable[[], list]) – A function that creates the metadata for requests.
  • timeout (int) – The default timeout, in seconds, for calls made through this client
  • app_name (string) – The codename of the calling service.
  • app_version (string) – The version of the calling service.
Returns:

A LoggingServiceV2Api object.

DEFAULT_SERVICE_PORT = 443

The default port of the service.

SERVICE_ADDRESS = 'logging.googleapis.com'

The default address of the service.

delete_log(log_name, options=None)[source]

Deletes a log and all its log entries. The log will reappear if it receives new entries.

Example

>>> from google.logging.v2.logging_service_v2_api import LoggingServiceV2Api
>>> api = LoggingServiceV2Api()
>>> log_name = api.log_path('[PROJECT]', '[LOG]')
>>> api.delete_log(log_name)
Parameters:
  • log_name (string) – Required. The resource name of the log to delete. Example: "projects/my-project/logs/syslog".
  • options (google.gax.CallOptions) – Overrides the default settings for this call, e.g, timeout, retries etc.
Raises:

google.gax.errors.GaxError if the RPC is aborted.

list_log_entries(project_ids, filter_='', order_by='', page_size=0, options=None)[source]

Lists log entries. Use this method to retrieve log entries from Cloud Logging. For ways to export log entries, see Exporting Logs.

Example

>>> from google.logging.v2.logging_service_v2_api import LoggingServiceV2Api
>>> from google.gax import CallOptions, INITIAL_PAGE
>>> api = LoggingServiceV2Api()
>>> project_ids = []
>>>
>>> # Iterate over all results
>>> for element in api.list_log_entries(project_ids):
>>>   # process element
>>>   pass
>>>
>>> # Or iterate over results one page at a time
>>> for page in api.list_log_entries(project_ids, options=CallOptions(page_token=INITIAL_PAGE)):
>>>   for element in page:
>>>     # process element
>>>     pass
Parameters:
  • project_ids (list[string]) – Required. One or more project IDs or project numbers from which to retrieve log entries. Examples of a project ID: "my-project-1A", "1234567890".
  • filter (string) – Optional. An advanced logs filter. The filter is compared against all log entries in the projects specified by projectIds. Only entries that match the filter are retrieved. An empty filter matches all log entries.
  • order_by (string) – Optional. How the results should be sorted. Presently, the only permitted values are "timestamp asc" (default) and "timestamp desc". The first option returns entries in order of increasing values of LogEntry.timestamp (oldest first), and the second option returns entries in order of decreasing timestamps (newest first). Entries with equal timestamps are returned in order of LogEntry.insertId.
  • page_size (int) – The maximum number of resources contained in the underlying API response. If page streaming is performed per- resource, this parameter does not affect the return value. If page streaming is performed per-page, this determines the maximum number of resources in a page.
  • options (google.gax.CallOptions) – Overrides the default settings for this call, e.g, timeout, retries etc.
Returns:

A google.gax.PageIterator instance. By default, this is an iterable of google.logging.v2.log_entry_pb2.LogEntry instances. This object can also be configured to iterate over the pages of the response through the CallOptions parameter.

Raises:

google.gax.errors.GaxError if the RPC is aborted.

list_monitored_resource_descriptors(page_size=0, options=None)[source]

Lists the monitored resource descriptors used by Stackdriver Logging.

Example

>>> from google.logging.v2.logging_service_v2_api import LoggingServiceV2Api
>>> from google.gax import CallOptions, INITIAL_PAGE
>>> api = LoggingServiceV2Api()
>>>
>>> # Iterate over all results
>>> for element in api.list_monitored_resource_descriptors():
>>>   # process element
>>>   pass
>>>
>>> # Or iterate over results one page at a time
>>> for page in api.list_monitored_resource_descriptors(options=CallOptions(page_token=INITIAL_PAGE)):
>>>   for element in page:
>>>     # process element
>>>     pass
Parameters:
  • page_size (int) – The maximum number of resources contained in the underlying API response. If page streaming is performed per- resource, this parameter does not affect the return value. If page streaming is performed per-page, this determines the maximum number of resources in a page.
  • options (google.gax.CallOptions) – Overrides the default settings for this call, e.g, timeout, retries etc.
Returns:

A google.gax.PageIterator instance. By default, this is an iterable of google.api.monitored_resource_pb2.MonitoredResourceDescriptor instances. This object can also be configured to iterate over the pages of the response through the CallOptions parameter.

Raises:

google.gax.errors.GaxError if the RPC is aborted.

classmethod log_path(project, log)[source]

Returns a fully-qualified log resource name string.

classmethod match_log_from_log_name(log_name)[source]

Parses the log from a log resource.

Parameters:log_name (string) – A fully-qualified path representing a log resource.
Returns:A string representing the log.
classmethod match_project_from_log_name(log_name)[source]

Parses the project from a log resource.

Parameters:log_name (string) – A fully-qualified path representing a log resource.
Returns:A string representing the project.
classmethod match_project_from_project_name(project_name)[source]

Parses the project from a project resource.

Parameters:project_name (string) – A fully-qualified path representing a project resource.
Returns:A string representing the project.
classmethod project_path(project)[source]

Returns a fully-qualified project resource name string.

write_log_entries(entries, log_name='', resource=None, labels=None, partial_success=False, options=None)[source]

Writes log entries to Stackdriver Logging. All log entries are written by this method.

Example

>>> from google.logging.v2.logging_service_v2_api import LoggingServiceV2Api
>>> from google.logging.v2 import logging_pb2
>>> api = LoggingServiceV2Api()
>>> entries = []
>>> response = api.write_log_entries(entries)
Parameters:
  • log_name (string) – Optional. A default log resource name for those log entries in entries that do not specify their own logName. Example: "projects/my-project/logs/syslog". See LogEntry.
  • resource (google.api.monitored_resource_pb2.MonitoredResource) – Optional. A default monitored resource for those log entries in entries that do not specify their own resource.
  • labels (dict[string -> google.logging.v2.logging_pb2.WriteLogEntriesRequest.LabelsEntry]) – Optional. User-defined key:value items that are added to the labels field of each log entry in entries, except when a log entry specifies its own key:value item with the same key. Example: { "size": "large", "color":"red" }
  • entries (list[google.logging.v2.log_entry_pb2.LogEntry]) –

    Required. The log entries to write. The log entries must have values for all required fields.

    To improve throughput and to avoid exceeding the quota limit for calls to entries.write, use this field to write multiple log entries at once rather than // calling this method for each log entry.

  • partial_success (bool) – Optional. Whether valid entries should be written even if some other entries fail due to INVALID_ARGUMENT or PERMISSION_DENIED errors. If any entry is not written, the response status will be the error associated with one of the failed entries and include error details in the form of WriteLogEntriesPartialErrors.
  • options (google.gax.CallOptions) – Overrides the default settings for this call, e.g, timeout, retries etc.
Raises:

google.gax.errors.GaxError if the RPC is aborted.