Skip to content

Commit f0c82ba

Browse files
authored
Merge pull request #1848 from waprin/master
logger.list_entries optimization using equals and docs update
2 parents 17bd49d + ea2a907 commit f0c82ba

3 files changed

Lines changed: 15 additions & 12 deletions

File tree

docs/logging-usage.rst

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ Fetch entries for the default project.
6565
>>> entries, token = client.list_entries() # API call
6666
>>> for entry in entries:
6767
... timestamp = entry.timestamp.isoformat()
68-
... print('%sZ: %s | %s' %
69-
... (timestamp, entry.text_payload, entry.struct_payload))
68+
... print('%sZ: %s' %
69+
... (timestamp, entry.payload))
7070
2016-02-17T20:35:49.031864072Z: A simple entry | None
7171
2016-02-17T20:38:15.944418531Z: None | {'message': 'My second entry', 'weather': 'partly cloudy'}
7272

@@ -129,7 +129,7 @@ Delete all entries for a logger
129129
>>> from gcloud import logging
130130
>>> client = logging.Client()
131131
>>> logger = client.logger('log_name')
132-
>>> logger.delete_entries() # API call
132+
>>> logger.delete() # API call
133133

134134

135135
Manage log metrics
@@ -220,8 +220,8 @@ Create a Cloud Storage sink:
220220
>>> client = logging.Client()
221221
>>> sink = client.sink(
222222
... "robots-storage",
223-
... filter='log:apache-access AND textPayload:robot')
224-
>>> sink.storage_bucket = "my-bucket-name"
223+
... 'log:apache-access AND textPayload:robot',
224+
... 'storage.googleapis.com/my-bucket-name')
225225
>>> sink.exists() # API call
226226
False
227227
>>> sink.create() # API call
@@ -236,8 +236,8 @@ Create a BigQuery sink:
236236
>>> client = logging.Client()
237237
>>> sink = client.sink(
238238
... "robots-bq",
239-
... filter='log:apache-access AND textPayload:robot')
240-
>>> sink.bigquery_dataset = "projects/my-project/datasets/my-dataset"
239+
... 'log:apache-access AND textPayload:robot',
240+
... 'bigquery.googleapis.com/projects/projects/my-project/datasets/my-dataset')
241241
>>> sink.exists() # API call
242242
False
243243
>>> sink.create() # API call
@@ -250,10 +250,11 @@ Create a Cloud Pub/Sub sink:
250250

251251
>>> from gcloud import logging
252252
>>> client = logging.Client()
253+
253254
>>> sink = client.sink(
254255
... "robots-pubsub",
255-
... filter='log:apache-access AND textPayload:robot')
256-
>>> sink.pubsub_topic = 'projects/my-project/topics/my-topic'
256+
... 'log:apache-access AND textPayload:robot',
257+
... 'pubsub.googleapis.com/projects/my-project/topics/my-topic')
257258
>>> sink.exists() # API call
258259
False
259260
>>> sink.create() # API call

gcloud/logging/logger.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ def list_entries(self, projects=None, filter_=None, order_by=None,
298298
more entries can be retrieved with another call (pass that
299299
value as ``page_token``).
300300
"""
301-
log_filter = 'logName:%s' % (self.name,)
301+
log_filter = 'logName=%s' % (self.full_name,)
302302
if filter_ is not None:
303303
filter_ = '%s AND %s' % (filter_, log_filter)
304304
else:

gcloud/logging/test_logger.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,8 @@ def test_delete_w_alternate_client(self):
348348
def test_list_entries_defaults(self):
349349
LISTED = {
350350
'projects': None,
351-
'filter_': 'logName:%s' % (self.LOGGER_NAME),
351+
'filter_': 'logName=projects/%s/logs/%s' %
352+
(self.PROJECT, self.LOGGER_NAME),
352353
'order_by': None,
353354
'page_size': None,
354355
'page_token': None,
@@ -371,7 +372,8 @@ def test_list_entries_explicit(self):
371372
PAGE_SIZE = 42
372373
LISTED = {
373374
'projects': ['PROJECT1', 'PROJECT2'],
374-
'filter_': '%s AND logName:%s' % (FILTER, self.LOGGER_NAME),
375+
'filter_': '%s AND logName=projects/%s/logs/%s' %
376+
(FILTER, self.PROJECT, self.LOGGER_NAME),
375377
'order_by': DESCENDING,
376378
'page_size': PAGE_SIZE,
377379
'page_token': TOKEN,

0 commit comments

Comments
 (0)