google.cloud.gapic.logging.v2.logging_service_v2_client

Accesses the google.logging.v2 LoggingServiceV2 API.

Classes

LoggingServiceV2Client([service_path, port, ...]) Service for ingesting and querying logs.
class google.cloud.gapic.logging.v2.logging_service_v2_client.LoggingServiceV2Client(service_path='logging.googleapis.com', port=443, channel=None, credentials=None, ssl_credentials=None, scopes=None, client_config=None, app_name='gax', app_version='0.15.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.Channel) – A Channel instance through which to make calls.
  • credentials (object) – The authorization credentials to attach to requests. These credentials identify this application to the service.
  • ssl_credentials (grpc.ChannelCredentials) – A ChannelCredentials instance for use with an SSL-enabled channel.
  • scopes (list[string]) – A list of OAuth2 scopes to attach to requests.
  • 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.
  • app_name (string) – The codename of the calling service.
  • app_version (string) – The version of the calling service.
Returns:

A LoggingServiceV2Client 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 all the log entries in a log. The log reappears if it receives new entries.

Example

>>> from google.cloud.gapic.logging.v2 import logging_service_v2_client
>>> api = logging_service_v2_client.LoggingServiceV2Client()
>>> 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:

    "projects/[PROJECT_ID]/logs/[LOG_ID]"
    "organizations/[ORGANIZATION_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". For more information about log names, see LogEntry.

  • options (google.gax.CallOptions) – Overrides the default settings for this call, e.g, timeout, retries etc.
Raises:
list_log_entries(resource_names, project_ids=None, 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.cloud.gapic.logging.v2 import logging_service_v2_client
>>> from google.gax import CallOptions, INITIAL_PAGE
>>> api = logging_service_v2_client.LoggingServiceV2Client()
>>> resource_names = []
>>>
>>> # Iterate over all results
>>> for element in api.list_log_entries(resource_names):
>>>   # process element
>>>   pass
>>>
>>> # Or iterate over results one page at a time
>>> for page in api.list_log_entries(resource_names, options=CallOptions(page_token=INITIAL_PAGE)):
>>>   for element in page:
>>>     # process element
>>>     pass
Parameters:
  • project_ids (list[string]) – Deprecated. One or more project identifiers or project numbers from which to retrieve log entries. Example: "my-project-1A". If present, these project identifiers are converted to resource format and added to the list of resources in resourceNames. Callers should use resourceNames rather than this parameter.
  • resource_names (list[string]) –

    Required. One or more cloud resources from which to retrieve log entries:

    "projects/[PROJECT_ID]"
    "organizations/[ORGANIZATION_ID]"
    

    Projects listed in the project_ids field are added to this list.

  • filter (string) – Optional. A filter that chooses which log entries to return. See [Advanced Logs Filters](/logging/docs/view/advanced_filters). Only log entries that match the filter are returned. An empty filter matches all log entries. The maximum length of the filter is 20000 characters.
  • 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.cloud.grpc.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:
list_monitored_resource_descriptors(page_size=0, options=None)[source]

Lists the monitored resource descriptors used by Stackdriver Logging.

Example

>>> from google.cloud.gapic.logging.v2 import logging_service_v2_client
>>> from google.gax import CallOptions, INITIAL_PAGE
>>> api = logging_service_v2_client.LoggingServiceV2Client()
>>>
>>> # 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:
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_parent_name(parent_name)[source]

Parses the project from a parent resource.

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

Returns a fully-qualified parent 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.cloud.gapic.logging.v2 import logging_service_v2_client
>>> from google.cloud.grpc.logging.v2 import log_entry_pb2
>>> api = logging_service_v2_client.LoggingServiceV2Client()
>>> entries = []
>>> response = api.write_log_entries(entries)
Parameters:
  • log_name (string) –

    Optional. A default log resource name that is assigned to all log entries in entries that do not specify a value for log_name:

    "projects/[PROJECT_ID]/logs/[LOG_ID]"
    "organizations/[ORGANIZATION_ID]/logs/[LOG_ID]"
    

    [LOG_ID] must be URL-encoded. For example, "projects/my-project-id/logs/syslog" or "organizations/1234567890/logs/cloudresourcemanager.googleapis.com%2Factivity". For more information about log names, see LogEntry.

  • resource (google.api.monitored_resource_pb2.MonitoredResource) –

    Optional. A default monitored resource object that is assigned to all log entries in entries that do not specify a value for resource. Example:

    { "type": "gce_instance",
      "labels": {
        "zone": "us-central1-a", "instance_id": "00000000000000000000" }}
    

    See LogEntry.

  • labels (dict[string -> google.cloud.grpc.logging.v2.logging_pb2.WriteLogEntriesRequest.LabelsEntry]) – Optional. Default labels that are added to the labels field of all log entries in entries. If a log entry already has a label with the same key as a label in this parameter, then the log entry’s label is not changed. See LogEntry.
  • entries (list[google.cloud.grpc.logging.v2.log_entry_pb2.LogEntry]) –

    Required. The log entries to write. Values supplied for the fields log_name, resource, and labels in this entries.write request are added to those log entries that do not provide their own values for the fields.

    To improve throughput and to avoid exceeding the quota limit for calls to entries.write, you should write multiple log entries at once rather than calling this method for each individual 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.
Returns:

A google.cloud.grpc.logging.v2.logging_pb2.WriteLogEntriesResponse instance.

Raises: