Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 1.8k
#1577: allow logging protobuf entries#1661
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 4 commits into
googleapis:logging-api
from
tseaver:1577-logging-protobuf_load_dumpMar 26, 2016
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
5d48c65
Add 'Logger.log_proto'.
tseaver f6e9de8
Add 'ProtobufEntry.parse_message' helper.
tseaver 2de3e0a
Drop use of 'google.protobuf.unittest_pb2.BoolMessage'.
tseaver e9a01ea
Document 'ProtobufEntry.parse_message' mutates passed-in message in …
tseaver File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
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
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 |
|---|---|---|
| @@ -14,6 +14,10 @@ | ||
| """Define API Loggers.""" | ||
| import json | ||
| from google.protobuf.json_format import MessageToJson | ||
| class Logger(object): | ||
| """Loggers represent named targets for log entries. | ||
| @@ -89,7 +93,7 @@ def log_text(self, text, client=None): | ||
| method='POST', path='/entries:write', data=data) | ||
| def log_struct(self, info, client=None): | ||
| """API call: log a text message via a POST request | ||
| """API call: log a structured message via a POST request | ||
| See: | ||
| https://cloud.google.com/logging/docs/api/ref_v2beta1/rest/v2beta1/entries/write | ||
| @@ -115,6 +119,35 @@ def log_struct(self, info, client=None): | ||
| client.connection.api_request( | ||
| method='POST', path='/entries:write', data=data) | ||
| def log_proto(self, message, client=None): | ||
| """API call: log a protobuf message via a POST request | ||
| See: | ||
| https://cloud.google.com/logging/docs/api/ref_v2beta1/rest/v2beta1/entries/write | ||
| :type message: Protobuf message | ||
| :param message: the message to be logged | ||
| :type client: :class:`gcloud.logging.client.Client` or ``NoneType`` | ||
| :param client: the client to use. If not passed, falls back to the | ||
| ``client`` stored on the current logger. | ||
| """ | ||
| client = self._require_client(client) | ||
| as_json_str = MessageToJson(message) | ||
| as_json = json.loads(as_json_str) | ||
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. | ||
| data = { | ||
| 'entries': [{ | ||
| 'logName': self.full_name, | ||
| 'protoPayload': as_json, | ||
| 'resource': { | ||
| 'type': 'global', | ||
| }, | ||
| }], | ||
| } | ||
| client.connection.api_request( | ||
| method='POST', path='/entries:write', data=data) | ||
| def delete(self, client=None): | ||
| """API call: delete all entries in a logger via a DELETE request | ||
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
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.
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.