-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Convert logging doctest examples to testable snippets. #2675
Conversation
Move usage docs for integration with Python stdlib 'logging' module into a separate file, sorted in front of the relevant API docs.
|
||
|
||
It's possible to tie the Python :mod:`logging` module directly into Google Cloud Logging. To use it, | ||
create a :class:`CloudLoggingHandler <google.cloud.logging.CloudLoggingHandler>` instance from your |
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.
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.
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.
.. code-block:: python | ||
|
||
>>> import logging | ||
>>> import google.cloud.logging # Don't conflict with standard logging |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
>>> client = google.cloud.logging.Client() | ||
>>> handler = CloudLoggingHandler(client) | ||
>>> cloud_logger = logging.getLogger('cloudLogger') | ||
>>> cloud_logger.setLevel(logging.INFO) # defaults to WARN |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
||
.. code-block:: python | ||
|
||
>>> handler = CloudLoggingHandler(client, name="mycustomlog") |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
options, see the transports section. | ||
|
||
All logs will go to a single custom log, which defaults to "python". The name of the Python | ||
logger will be included in the structured log entry under the "python_logger" field. You can |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
FILTER = 'textPayload:robot' | ||
|
||
# [START sink_bigquery_create] | ||
DESTINATION = 'bigquery.googleapis.com%s' % (dataset.path) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
UPDATED_FILTER = 'textPayload:robot' | ||
|
||
# [START sink_pubsub_create] | ||
DESTINATION = 'pubsub.googleapis.com/%s' % (topic.full_name) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
def _find_examples(): | ||
funcs = [obj for obj in globals().values() | ||
if getattr(obj, '_snippet', False)] | ||
for func in sorted(funcs, key=_line_no): |
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.
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.
|
||
|
||
def _line_no(func): | ||
code = getattr(func, '__code__', None) or getattr(func, 'func_code') |
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.
except AssertionError as e: | ||
print(' FAIL: %s' % (e,)) | ||
except Exception as e: # pylint: disable=broad-except | ||
print(' ERROR: %r' % (e,)) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Convert logging doctest examples to testable snippets.
Move usage docs for integration with Python stdlib 'logging' module into a separate file, sorted in front of the relevant API docs.
Reworks #2556 after other merges (iterators, doctest removal) made fixing that PRs branch too painful.