Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

docs: Added documentation on log_level and excluded_loggers params in setup_logging #971

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

Merged
merged 3 commits into from
Mar 4, 2025
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 15 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 3 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 3 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 8 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
Morty Proxy This is a proxified and sanitized view of the page, visit original site.