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)