Skip to content
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

docs: update usage guide for v3.0.0 #456

Merged
merged 28 commits into from
Jan 26, 2022
Merged
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
a5c36d7
added empty v3.0.0 section to UPGRADING.md
daniel-sanche Dec 7, 2021
0ff7048
reorganized table of contents
daniel-sanche Dec 7, 2021
68e7f9d
marked old handlers as deprecated
daniel-sanche Dec 7, 2021
ff046f5
removed duplicated stdlib doc
daniel-sanche Dec 8, 2021
2e5fd18
made some progress on standard library integration doc
daniel-sanche Dec 8, 2021
51d2a9a
added more stdlib documentation
daniel-sanche Dec 8, 2021
fcc239b
finished up stdlib docs
daniel-sanche Dec 9, 2021
5826ce3
added page for direct API usage
daniel-sanche Dec 9, 2021
205d915
copied old usage guide info
daniel-sanche Dec 9, 2021
98a0a8c
working on setup section
daniel-sanche Dec 10, 2021
117e619
added log writing docs
daniel-sanche Dec 10, 2021
913a08c
removed references to POST requests
daniel-sanche Dec 10, 2021
29ea7d4
added batching info
daniel-sanche Dec 10, 2021
e822bd0
added transport docs
daniel-sanche Dec 10, 2021
8bce609
added grpc vs http docs
daniel-sanche Dec 10, 2021
eac5e2d
added upgrading notes
daniel-sanche Dec 14, 2021
01a0e33
improved manual handler section
daniel-sanche Jan 14, 2022
0526955
fixed lint issues
daniel-sanche Jan 15, 2022
a91b5f4
fixed snippet issue
daniel-sanche Jan 24, 2022
0ad37c8
addressed Drew's comments
daniel-sanche Jan 24, 2022
fd314b9
incorporated Pamela's feedback to migration guide
daniel-sanche Jan 25, 2022
95e5890
updated formatting
daniel-sanche Jan 26, 2022
51a7cd5
updated wording
daniel-sanche Jan 26, 2022
69209b1
changed wording
daniel-sanche Jan 26, 2022
741dfac
addressed Pamela's comments on the direct library usage document
daniel-sanche Jan 26, 2022
49dc3c3
incorporated Pamela's feedback in std lib integration doc
daniel-sanche Jan 26, 2022
ef947d3
removed unneeded delete lines
daniel-sanche Jan 26, 2022
1ff01aa
switched client for tests
daniel-sanche Jan 26, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
incorporated Pamela's feedback in std lib integration doc
  • Loading branch information
daniel-sanche committed Jan 26, 2022
commit 49dc3c304d1df7ac52209adaecfa6f267f2fb578
44 changes: 22 additions & 22 deletions docs/std-lib-integration.rst
Original file line number Diff line number Diff line change
@@ -1,32 +1,31 @@
Integration with `logging` Standard Library
===========================================

The recommended way to use :mod:`google-cloud-logging` is to allow it to integrate with
We recommend that you use :mod:`google-cloud-logging` to integrate with
the Python :mod:`logging` standard library. This way, you can write logs using Python
standards, and still have your logs appear in Google Cloud Logging using custom handlers
behind the scenes.
standards, and still have your logs appear in Google Cloud Logging.

Automatic Configuration
-----------------------

To integrate :mod:`google-cloud-logging` with the standard :mod:`logging` module,
simply call :meth:`~google.cloud.logging_v2.client.Client.setup_logging` on a :class:`~google.cloud.logging_v2.client.Client` instance.
call :meth:`~google.cloud.logging_v2.client.Client.setup_logging` on a :class:`~google.cloud.logging_v2.client.Client` instance.

.. literalinclude:: ../samples/snippets/handler.py
:start-after: [START logging_handler_setup]
:end-before: [END logging_handler_setup]
:dedent: 4

This function will automatically choose the best configurations for the environment your
This :meth:`~google.cloud.logging_v2.client.Client.setup_logging` function chooses the best configurations for the environment your
code is running on. For more information, see the `Google Cloud Logging documentation <https://cloud.google.com/logging/docs/setup/python>`_.

Manual Handler Configuration
-----------------------------

.. _Manual Handler:

Automatic Configuration will automatically determine the appropriate handler for the environment.
If you would rather choose the handler yourself, you can construct an instance manually and pass it in
Automatic Configuration automatically determines the appropriate handler for the environment.
To specify the handler yourself, construct an instance manually and pass it in
as an argument to :meth:`~google.cloud.logging_v2.handlers.setup_logging`:

.. literalinclude:: ../samples/snippets/usage_guide.py
Expand All @@ -45,11 +44,11 @@ There are two supported handler classes to choose from:
to standard out, to be read and parsed by a GCP logging agent
- This is the default handler on Kubernetes Engine, Cloud Functions and Cloud Run

Using the Standard Library
Standard Library
---------------------------

After the Google Cloug Logging library has been setup with the Python :mod:`logging` standard library,
you can begin to send logs with the standard logging library as you normally would:
After you setup the Google Cloud Logging library with the Python :mod:`logging` standard library,
you can send logs with the standard logging library as you normally would:

.. literalinclude:: ../samples/snippets/handler.py
:start-after: [START logging_handler_usage]
Expand All @@ -65,16 +64,17 @@ Logging JSON Payloads

Although the Python :mod:`logging` standard library `expects all logs to be strings <https://docs.python.org/3/library/logging.html#logging.Logger.debug>`_,
Google Cloud Logging allows `JSON payload data <https://cloud.google.com/logging/docs/structured-logging>`_.
You can write JSON logs using the standard library integration in one of the following ways:

1. Using the `json_fields` `extra` argument:
To write JSON logs using the standard library integration, do one of the following:

1. Use the `json_fields` `extra` argument:

.. literalinclude:: ../samples/snippets/usage_guide.py
:start-after: [START logging_extra_json_fields]
:end-before: [END logging_extra_json_fields]
:dedent: 4

2. Logging a JSON-parsable string:
2. Log a JSON-parsable string:

.. literalinclude:: ../samples/snippets/usage_guide.py
:start-after: [START logging_json_dumps]
Expand All @@ -87,9 +87,9 @@ Automatic Metadata Detection

.. _Autodetection:

The Google Cloud Logging library will attempt to detect and attach additional
`LogEntry fields <https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry>`_
whenever possible. The following fields are currently supported:
The Google Cloud Logging library attempts to detect and attach additional
`LogEntry fields <https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry>`_ .
The following fields are currently supported:

- labels
- trace*
Expand All @@ -101,14 +101,14 @@ whenever possible. The following fields are currently supported:
- :ref:`json_fields<JSON>`

.. note::
Fields marked with "*" can only be detected when using a supported Python web framework. The Google Cloud Logging
Fields marked with "*" require a supported Python web framework. The Google Cloud Logging
library currently supports `flask <https://flask.palletsprojects.com/>`_ and `django <https://www.djangoproject.com/>`_

Manual Metadata Using the `extra` Argument
------------------------------------------
--------------------------------------------

The Python :mod:`logging` standard library accepts `an "extra" argument <https://docs.python.org/3/library/logging.html#logging.Logger.debug>`_ when
writing logs, which can be used to populate LogRecord objects with user-defined
writing logs. You can use this argument to populate LogRecord objects with user-defined
key-value pairs. Google Cloud Logging uses the `extra` field as a way to pass in additional
metadata to populate `LogEntry fields <https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry>`_.

Expand All @@ -119,15 +119,15 @@ metadata to populate `LogEntry fields <https://cloud.google.com/logging/docs/ref

All of the `LogEntry fields <https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry>`_
that can be :ref:`autodetected<Autodetection>` can also be set manually through the `extra` argument. Fields sent explicitly through the `extra`
argument will override any :ref:`automatically detected<Autodetection>` fields.
argument override any :ref:`automatically detected<Autodetection>` fields.

CloudLoggingHandler Transports
------------------------------

.. _Transports:

:doc:`Transport</transport>` classes define how the :class:`~google.cloud.logging_v2.handlers.handlers.CloudLoggingHandler`
transports logs over the network to GCP. There are currently two Transport implementations
transports logs over the network to Google Cloud. There are two Transport implementations
(defined as subclasses of :class:`transports.base.Transport <google.cloud.logging_v2.handlers.transports.base.Transport>`):

- :class:`~google.cloud.logging_v2.handlers.transports.background_thread.BackgroundThreadTransport`:
Expand All @@ -139,7 +139,7 @@ transports logs over the network to GCP. There are currently two Transport imple
You can set a Transport class by passing it as an argument when
:ref:`initializing CloudLoggingHandler manually.<manual handler>`

Both options can be used over either :doc:`gRPC or HTTP</grpc-vs-http>`.
You can use both transport options over :doc:`gRPC or HTTP</grpc-vs-http>`.

.. note::
:class:`~google.cloud.logging_v2.handlers.structured_log.StructuredLogHandler`
Expand Down