-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Add 'Client.list_entries'. #1569
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
tseaver
merged 1 commit into
googleapis:logging-api
from
tseaver:logging-client_list_entries
Mar 11, 2016
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -113,6 +113,7 @@ | |
| logging-usage | ||
| Client <logging-client> | ||
| logging-logger | ||
| logging-entries | ||
|
|
||
| .. toctree:: | ||
| :maxdepth: 0 | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| Entries | ||
| ======= | ||
|
|
||
| .. automodule:: gcloud.logging.entries | ||
| :members: | ||
| :undoc-members: | ||
| :show-inheritance: | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,3 +19,5 @@ | |
|
|
||
|
|
||
| SCOPE = Connection.SCOPE | ||
| ASCENDING = 'timestamp asc' | ||
| DESCENDING = 'timestamp desc' | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| # Copyright 2016 Google Inc. All rights reserved. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| """Helper functions for shared behavior.""" | ||
|
|
||
| import re | ||
|
|
||
| from gcloud._helpers import _name_from_project_path | ||
|
|
||
|
|
||
| _LOGGER_TEMPLATE = re.compile(r""" | ||
| projects/ # static prefix | ||
| (?P<project>[^/]+) # initial letter, wordchars + hyphen | ||
| /logs/ # static midfix | ||
| (?P<name>[^/]+) # initial letter, wordchars + allowed punc | ||
| """, re.VERBOSE) | ||
|
|
||
|
|
||
| def logger_name_from_path(path, project): | ||
| """Validate a logger URI path and get the logger name. | ||
|
|
||
| :type path: string | ||
| :param path: URI path for a logger API request. | ||
|
|
||
| :type project: string | ||
| :param project: The project associated with the request. It is | ||
| included for validation purposes. | ||
|
|
||
| :rtype: string | ||
| :returns: Topic name parsed from ``path``. | ||
| :raises: :class:`ValueError` if the ``path`` is ill-formed or if | ||
| the project from the ``path`` does not agree with the | ||
| ``project`` passed in. | ||
| """ | ||
| return _name_from_project_path(path, project, _LOGGER_TEMPLATE) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| # Copyright 2016 Google Inc. All rights reserved. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| """Log entries within the Google Cloud Logging API.""" | ||
|
|
||
| from gcloud._helpers import _rfc3339_nanos_to_datetime | ||
| from gcloud.logging._helpers import logger_name_from_path | ||
|
|
||
|
|
||
| class _BaseEntry(object): | ||
| """Base class for TextEntry, StructEntry. | ||
|
|
||
| :type payload: text or dict | ||
| :param payload: The payload passed as ``textPayload``, ``jsonPayload``, | ||
| or ``protoPayload``. | ||
|
|
||
| :type logger: :class:`gcloud.logging.logger.Logger` | ||
| :param logger: the logger used to write the entry. | ||
|
|
||
| :type insert_id: text, or :class:`NoneType` | ||
| :param insert_id: (optional) the ID used to identify an entry uniquely. | ||
|
|
||
| :type timestamp: :class:`datetime.datetime`, or :class:`NoneType` | ||
| :param timestamp: (optional) timestamp for the entry | ||
| """ | ||
| def __init__(self, payload, logger, insert_id=None, timestamp=None): | ||
| self.payload = payload | ||
| self.logger = logger | ||
| self.insert_id = insert_id | ||
| self.timestamp = timestamp | ||
|
|
||
| @classmethod | ||
| def from_api_repr(cls, resource, client, loggers=None): | ||
| """Factory: construct an entry given its API representation | ||
|
|
||
| :type resource: dict | ||
| :param resource: text entry resource representation returned from | ||
| the API | ||
|
|
||
| :type client: :class:`gcloud.logging.client.Client` | ||
| :param client: Client which holds credentials and project | ||
| configuration. | ||
|
|
||
| :type loggers: dict or None | ||
| :param loggers: A mapping of logger fullnames -> loggers. If not | ||
| passed, the entry will have a newly-created logger. | ||
|
|
||
| :rtype: :class:`gcloud.logging.entries.TextEntry` | ||
| :returns: Text entry parsed from ``resource``. | ||
| """ | ||
| if loggers is None: | ||
| loggers = {} | ||
| logger_fullname = resource['logName'] | ||
| logger = loggers.get(logger_fullname) | ||
| if logger is None: | ||
| logger_name = logger_name_from_path( | ||
| logger_fullname, client.project) | ||
| logger = loggers[logger_fullname] = client.logger(logger_name) | ||
| payload = resource[cls._PAYLOAD_KEY] | ||
| insert_id = resource.get('insertId') | ||
| timestamp = resource.get('timestamp') | ||
| if timestamp is not None: | ||
| timestamp = _rfc3339_nanos_to_datetime(timestamp) | ||
| return cls(payload, logger, insert_id, timestamp) | ||
|
|
||
|
|
||
| class TextEntry(_BaseEntry): | ||
| """Entry created via a write request with ``textPayload``. | ||
|
|
||
| See: | ||
| https://cloud.google.com/logging/docs/api/ref_v2beta1/rest/v2beta1/LogEntry | ||
| """ | ||
| _PAYLOAD_KEY = 'textPayload' | ||
|
|
||
|
|
||
| class StructEntry(_BaseEntry): | ||
| """Entry created via a write request with ``jsonPayload``. | ||
|
|
||
| See: | ||
| https://cloud.google.com/logging/docs/api/ref_v2beta1/rest/v2beta1/LogEntry | ||
| """ | ||
| _PAYLOAD_KEY = 'jsonPayload' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| # Copyright 2016 Google Inc. All rights reserved. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| import unittest2 | ||
|
|
||
|
|
||
| class Test_logger_name_from_path(unittest2.TestCase): | ||
|
|
||
| def _callFUT(self, path, project): | ||
| from gcloud.logging._helpers import logger_name_from_path | ||
| return logger_name_from_path(path, project) | ||
|
|
||
| def test_w_simple_name(self): | ||
| LOGGER_NAME = 'LOGGER_NAME' | ||
| PROJECT = 'my-project-1234' | ||
| PATH = 'projects/%s/logs/%s' % (PROJECT, LOGGER_NAME) | ||
| logger_name = self._callFUT(PATH, PROJECT) | ||
| self.assertEqual(logger_name, LOGGER_NAME) | ||
|
|
||
| def test_w_name_w_all_extras(self): | ||
| LOGGER_NAME = 'LOGGER_NAME-part.one~part.two%part-three' | ||
| PROJECT = 'my-project-1234' | ||
| PATH = 'projects/%s/logs/%s' % (PROJECT, LOGGER_NAME) | ||
| logger_name = self._callFUT(PATH, PROJECT) | ||
| self.assertEqual(logger_name, LOGGER_NAME) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.