-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Add a timestamp parameter to the logger. #2860
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
Conversation
… one sends batches of log records. In this case, each log record in a batch will have the same timestamp. This timestamp would be the timestamp of insertion in the google cloud logging API.
|
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed, please reply here (e.g.
|
|
I signed it! |
|
CLAs look good, thanks! |
|
@Fkawala, I noticed that timestamp is always There are helper functions in |
|
@Fkawala, @daspecster The |
|
@waprin PTAL |
|
@daspecster @tseaver I'll update the PR to use |
… timestamp to a RFC3339 string representation in the helper function _make_entry_resource.
|
@Fkawala I think you should convert it as close to receiving it as possible. @tseaver in thinking about this more, should the Otherwise the example would be something like from datetime import datetime
logger.log_text("A simple entry", timestamp=datetime.utcnow())Or something similar to that. |
|
@daspecster Can I get closer than I did in 7ac9c0a ? |
|
@Fkawala if a datetime object gets passed to the As I mentioned above, this depends on what we want our usage to look like. |
|
@Fkawala The |
|
@daspecster ok got it, thanks for the explanation. I'll update the PR If the string compatibility is needed for the Is there something I could do to for the PR to pass the CI tests ? |
|
@Fkawala I think the issue with the Python 3 tests has been resolved. I'll restart the build and see if they clear up. |
|
lgtm |
logging/unit_tests/test_logger.py
Outdated
| batch.log_struct(STRUCT) | ||
| self.assertEqual(batch.entries, | ||
| [('struct', STRUCT, None, None, None, None)]) | ||
| [('struct', STRUCT, None, None, None, None, None)]) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
logging/unit_tests/test_logger.py
Outdated
| batch.log_struct(STRUCT, labels=LABELS, insert_id=IID, | ||
| severity=SEVERITY, http_request=REQUEST) | ||
| severity=SEVERITY, http_request=REQUEST, timestamp=TIMESTAMP) | ||
| self.assertEqual(batch.entries, |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
logging/unit_tests/test_logger.py
Outdated
| severity=SEVERITY, http_request=REQUEST, timestamp=TIMESTAMP) | ||
| self.assertEqual(batch.entries, | ||
| [('struct', STRUCT, LABELS, IID, SEVERITY, REQUEST)]) | ||
| [('struct', STRUCT, LABELS, IID, SEVERITY, REQUEST, TIMESTAMP)]) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
logging/unit_tests/test_logger.py
Outdated
| batch = self._make_one(logger, client=client) | ||
| batch.log_proto(message, labels=LABELS, insert_id=IID, | ||
| severity=SEVERITY, http_request=REQUEST) | ||
| severity=SEVERITY, http_request=REQUEST, timestamp=TIMESTAMP) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
logging/unit_tests/test_logger.py
Outdated
| severity=SEVERITY, http_request=REQUEST, timestamp=TIMESTAMP) | ||
| self.assertEqual(batch.entries, | ||
| [('proto', message, LABELS, IID, SEVERITY, REQUEST)]) | ||
| [('proto', message, LABELS, IID, SEVERITY, REQUEST, TIMESTAMP)]) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
@Fkawala now we're cooking with Ci! You're missing some test coverage in And the issues that @tseaver mentioned can be seen here You can run the tests, lint and coverage commands as mentioned in the $ tox -e py27 -- logging
$ tox -e py35 -- logging
$ tox -e cover -- logging
$ tox -e lint |
… timestamps were string instead of :class:`datetime.datetime`.
|
@daspecster Thanks for the explanation! |
| entries = [] | ||
| for entry_type, entry, labels, iid, severity, http_req, timestamp in self.entries: | ||
| for entry_type, entry, labels, iid, severity, http_req, timestamp in \ | ||
| self.entries: |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
@Fkawala Thank you for the patch! |
|
@tseaver I'm happy to contribute, you do truly great work here, thanks! |
|
@tseaver, I don't know about the release patterns for this project, when should I expect a release for google.cloud.logging ? |
|
Releasing is pretty easy for us, though we probably won't do it until the new year. |
|
@tseaver That's pretty likely. Though I want to break off some more chunks before doing a release (e.g. make |
|
Hi, any update on the expected release of #2860 ? |
The timestamp parameter is useful when one sends batches of log records. In this case, every log record in a batch will have the same timestamp. The timestamp equals the date of insertion in the google cloud logging API.
If one uses the
asctimeattribute from the LogRecord instances as timestamp value, a log record would have a propre date.