FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Convert logging doctest examples to testable snippets. by tseaver · Pull Request #2675 · googleapis/google-cloud-python · GitHub

Convert logging doctest examples to testable snippets. - #2675

Merged
tseaver merged 3 commits into
googleapis:masterfrom
tseaver:logging-snippets
Nov 7, 2016
Merged

Convert logging doctest examples to testable snippets.#2675
tseaver merged 3 commits into
googleapis:masterfrom
tseaver:logging-snippets

Conversation

tseaver commented Nov 3, 2016

Copy link
Copy Markdown
Contributor

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.

Move usage docs for integration with Python stdlib 'logging' module into
a separate file, sorted in front of the relevant API docs.
tseaver added docs testing api: logging Issues related to the Cloud Logging API. labels Nov 3, 2016
googlebot added the cla: yes This human has signed the Contributor License Agreement. label Nov 3, 2016


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.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

.. code-block:: python

>>> import logging
>>> import google.cloud.logging # Don't conflict with standard logging

This comment was marked as spam.

>>> 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.


.. code-block:: python

>>> handler = CloudLoggingHandler(client, name="mycustomlog")

This comment was marked as spam.

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.

Comment thread docs/logging_snippets.py Outdated
FILTER = 'textPayload:robot'

# [START sink_bigquery_create]
DESTINATION = 'bigquery.googleapis.com%s' % (dataset.path)

This comment was marked as spam.

Comment thread docs/logging_snippets.py Outdated
UPDATED_FILTER = 'textPayload:robot'

# [START sink_pubsub_create]
DESTINATION = 'pubsub.googleapis.com/%s' % (topic.full_name)

This comment was marked as spam.

Comment thread docs/logging_snippets.py
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.

This comment was marked as spam.

This comment was marked as spam.

Comment thread docs/logging_snippets.py Outdated


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.

Comment thread docs/logging_snippets.py Outdated
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.

tseaver merged commit 8b899d1 into googleapis:master Nov 7, 2016
tseaver deleted the logging-snippets branch November 7, 2016 20:55
richkadel pushed a commit to richkadel/google-cloud-python that referenced this pull request May 6, 2017
Convert logging doctest examples to testable snippets.
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: logging Issues related to the Cloud Logging API. cla: yes This human has signed the Contributor License Agreement. testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants


Back | FazBrowse Home | New Git URL