Skip to content
This repository was archived by the owner on Aug 13, 2026. It is now read-only.
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
finished up stdlib docs
  • Loading branch information
daniel-sanche committed Dec 9, 2021
commit fcc239bc29e815f6d2d3d71ee35e0d4d429e0965
73 changes: 41 additions & 32 deletions docs/std-lib-integration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,7 @@ simply call :meth:`setup_logging` on a :class:`~google.cloud.logging.client.Clie
:dedent: 4

This function will automatically choose the best configurations for the environment your
code is running on. After running :meth:`setup_logging`, you can write logs using the
standard :mod:`logging` module as normal:

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

For more information on the library, see the `Google Cloud Logging documentation <https://cloud.google.com/logging/docs/setup/python>`_.
For more information on the Python :mod:`logging` standard library, see the `logging documentation <https://docs.python.org/3/howto/logging.html#a-simple-example>`_
code is running on. For more information, see the `Google Cloud Logging documentation <https://cloud.google.com/logging/docs/setup/python>`_.

Manual Handler Configuration
-----------------------------
Expand All @@ -53,6 +44,19 @@ There are two supported handler classes to choose from:

.. _JSON:

Using the 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:

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

For more information on using the Python :mod:`logging` standard library, see the `logging documentation <https://docs.python.org/3/howto/logging.html#a-simple-example>`_

Logging JSON Payloads
----------------------

Expand All @@ -74,38 +78,43 @@ You can write JSON logs using the standard library integration in one of the fol
:end-before: [END logging_json_dumps]
:dedent: 4

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
key-value pairs. Google Cloud Logging uses the `extra` field as a way to pass in
metadata to populate `LogEntry fields <https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry>`_.

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

Automatic Metadata Detection
----------------------------

The following `LogEntry fields <https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry>`_
can be set through the `extra` argument:
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:

- labels
- trace
- span_id
- trace_sampled
- http_request
- trace*
- span_id*
- trace_sampled*
- http_request*
- source_location
- resource
- :ref:`json_fields<JSON>`

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

Metadata sent explicitly through the `extra` argument will override any :ref:`automatically detected<Autodetection>` fields.
Manual Metadata Using the `extra` Argument
------------------------------------------

.. _Autodetection:
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
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>`_.

Automatic Metadata Detection
----------------------------
.. literalinclude:: ../samples/snippets/usage_guide.py
:start-after: [START logging_extras]
:end-before: [END logging_extras]
:dedent: 4

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.