From 62641075042a3da9bb9c059d963bad14a1586b1c Mon Sep 17 00:00:00 2001 From: Kevin Zheng <147537668+gkevinzheng@users.noreply.github.com> Date: Wed, 24 Apr 2024 11:39:24 -0400 Subject: [PATCH] docs: Update `dictConfig` snippet (#885) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * docs: Update `dictConfig` snippet to add line that applies the config * Added `import logging.config` into snippet * Update root handlers dict entry in dictConfig * Update usage_guide.py * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * Remove propagate config option from loggers * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * Added test for dictConfig snippet * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --------- Co-authored-by: Owl Bot --- samples/snippets/usage_guide.py | 17 ++++++++++------- samples/snippets/usage_guide_test.py | 6 ++++++ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/samples/snippets/usage_guide.py b/samples/snippets/usage_guide.py index f4292a9de..ef8847ba5 100644 --- a/samples/snippets/usage_guide.py +++ b/samples/snippets/usage_guide.py @@ -486,9 +486,9 @@ def setup_logging(client): @snippet def logging_dict_config(client): + # [START logging_dict_config] import logging.config - # [START logging_dict_config] import google.cloud.logging client = google.cloud.logging.Client() @@ -496,23 +496,26 @@ def logging_dict_config(client): LOGGING = { "version": 1, "handlers": { - "cloud_logging": { + "cloud_logging_handler": { "class": "google.cloud.logging.handlers.CloudLoggingHandler", "client": client, }, - "structured_log": { + "structured_log_handler": { "class": "google.cloud.logging.handlers.StructuredLogHandler" }, }, - "root": {"handlers": ["console"], "level": "WARNING"}, + "root": {"handlers": [], "level": "WARNING"}, "loggers": { - "my_logger": {"handlers": ["cloud_logging"], "level": "INFO"}, - "my_other_logger": {"handlers": ["structured_log"], "level": "INFO"}, + "cloud_logger": {"handlers": ["cloud_logging_handler"], "level": "INFO"}, + "structured_logger": { + "handlers": ["structured_log_handler"], + "level": "INFO", + }, }, } - # [END logging_dict_config] logging.config.dictConfig(LOGGING) + # [END logging_dict_config] def _line_no(func): diff --git a/samples/snippets/usage_guide_test.py b/samples/snippets/usage_guide_test.py index f02d82fbd..3f606dd65 100644 --- a/samples/snippets/usage_guide_test.py +++ b/samples/snippets/usage_guide_test.py @@ -88,3 +88,9 @@ def test_client_list_entries(): for item in to_delete: usage_guide._backoff_not_found(item.delete) + + +def test_dict_config(): + client = Client() + + usage_guide.logging_dict_config(client)