Skip to content

Commit

Permalink
docs: Update dictConfig snippet (#885)
Browse files Browse the repository at this point in the history
* 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 <gcf-owl-bot[bot]@users.noreply.github.com>
  • Loading branch information
gkevinzheng and gcf-owl-bot[bot] committed Apr 24, 2024
1 parent 9c5e8f0 commit 6264107
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
17 changes: 10 additions & 7 deletions samples/snippets/usage_guide.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,33 +486,36 @@ 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()

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):
Expand Down
6 changes: 6 additions & 0 deletions samples/snippets/usage_guide_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 6264107

Please sign in to comment.