Skip to content

Conversation

@tseaver
Copy link
Contributor

@tseaver tseaver commented Nov 3, 2016

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 tseaver added docs testing api: logging Issues related to the Cloud Logging API. labels Nov 3, 2016
@googlebot 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.

FILTER = 'textPayload:robot'

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

This comment was marked as spam.

UPDATED_FILTER = 'textPayload:robot'

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

This comment was marked as spam.

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.



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.

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 tseaver merged commit 8b899d1 into googleapis:master Nov 7, 2016
@tseaver 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.
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