Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
15 changes: 15 additions & 0 deletions docs/std-lib-integration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,21 @@ call :meth:`~google.cloud.logging_v2.client.Client.setup_logging` on a :class:`~
:end-before: [END logging_handler_setup]
:dedent: 4


You can also set the logging level threshold of the logging handler created by :meth:`~google.cloud.logging_v2.client.Client.setup_logging`,
as well as set loggers excluded from the logger that is created:

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

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


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

Expand Down
3 changes: 2 additions & 1 deletion google/cloud/logging_v2/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,8 @@ def setup_logging(
loggers, will report to Cloud Logging.

Args:
log_level (Optional[int]): Python logging log level. Defaults to
log_level (Optional[int]): The logging level threshold of the attached logger,
as set by the :meth:`logging.Logger.setLevel` method. Defaults to
:const:`logging.INFO`.
excluded_loggers (Optional[Tuple[str]]): The loggers to not attach the
handler to. This will always include the
Expand Down
3 changes: 2 additions & 1 deletion google/cloud/logging_v2/handlers/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,8 @@ def setup_logging(
excluded_loggers (Optional[Tuple[str]]): The loggers to not attach the handler
to. This will always include the loggers in the
path of the logging client itself.
log_level (Optional[int]): Python logging log level. Defaults to
log_level (Optional[int]): The logging level threshold of the attached logger,
as set by the :meth:`logging.Logger.setLevel` method. Defaults to
:const:`logging.INFO`.
"""
all_excluded_loggers = set(excluded_loggers + _INTERNAL_LOGGERS)
Expand Down
8 changes: 4 additions & 4 deletions samples/snippets/usage_guide.py
Original file line number Diff line number Diff line change
Expand Up @@ -475,13 +475,13 @@ def using_extras(client):
def setup_logging(client):
import logging

# [START setup_logging]
# [START logging_setup_logging]
client.setup_logging(log_level=logging.INFO)
# [END setup_logging]
# [END logging_setup_logging]

# [START setup_logging_excludes]
# [START logging_setup_logging_excludes]
client.setup_logging(log_level=logging.INFO, excluded_loggers=("werkzeug",))
# [END setup_logging_excludes]
# [END logging_setup_logging_excludes]


@snippet
Expand Down