Skip to content
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

docs: Update dictConfig snippet #885

Merged
merged 9 commits into from Apr 24, 2024
Merged

docs: Update dictConfig snippet #885

merged 9 commits into from Apr 24, 2024

Conversation

gkevinzheng
Copy link
Contributor

@gkevinzheng gkevinzheng commented Apr 18, 2024

The previous dictConfig snippet did not include the proper include logging.config statement or logging.config.dictConfig statement in the snippet as seen in the documentation to actually apply the dictConfig. The configuration also did not run properly, failing with traceback

Traceback (most recent call last):
  File "/usr/local/google/home/kevzheng/.pyenv/versions/3.12.0/lib/python3.12/logging/config.py", line 872, in add_handlers
    logger.addHandler(self.config['handlers'][h])
                      ~~~~~~~~~~~~~~~~~~~~~~~^^^
  File "/usr/local/google/home/kevzheng/.pyenv/versions/3.12.0/lib/python3.12/logging/config.py", line 344, in __getitem__
    value = dict.__getitem__(self, key)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^
KeyError: 'console'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/local/google/home/kevzheng/.pyenv/versions/3.12.0/lib/python3.12/logging/config.py", line 660, in configure
    self.configure_root(root)
  File "/usr/local/google/home/kevzheng/.pyenv/versions/3.12.0/lib/python3.12/logging/config.py", line 906, in configure_root
    self.common_logger_config(root, config, incremental)
  File "/usr/local/google/home/kevzheng/.pyenv/versions/3.12.0/lib/python3.12/logging/config.py", line 889, in common_logger_config
    self.add_handlers(logger, handlers)
  File "/usr/local/google/home/kevzheng/.pyenv/versions/3.12.0/lib/python3.12/logging/config.py", line 874, in add_handlers
    raise ValueError('Unable to add handler %r' % h) from e
ValueError: Unable to add handler 'console'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/google/home/kevzheng/.pyenv/versions/3.12.0/lib/python3.12/logging/config.py", line 912, in dictConfig
    dictConfigClass(config).configure()
  File "/usr/local/google/home/kevzheng/.pyenv/versions/3.12.0/lib/python3.12/logging/config.py", line 662, in configure
    raise ValueError('Unable to configure root '
ValueError: Unable to configure root logger

This PR adds a more realistic sample dictConfig that might be used in an actual Cloud environment, while still maintaining how to set up both CloudLoggingHandler and StructuredLogHandler in dictConfig in a Cloud environment.

@gkevinzheng gkevinzheng requested review from a team as code owners April 18, 2024 15:59
@product-auto-label product-auto-label bot added the size: xs Pull request size is extra small. label Apr 18, 2024
@product-auto-label product-auto-label bot added the api: logging Issues related to the googleapis/python-logging API. label Apr 18, 2024
Copy link

snippet-bot bot commented Apr 18, 2024

Here is the summary of changes.

You are about to add 1 region tag.
You are about to delete 1 region tag.

This comment is generated by snippet-bot.
If you find problems with this result, please file an issue at:
https://github.com/googleapis/repo-automation-bots/issues.
To update this comment, add snippet-bot:force-run label or use the checkbox below:

  • Refresh this comment

@product-auto-label product-auto-label bot added size: s Pull request size is small. and removed size: xs Pull request size is extra small. labels Apr 18, 2024
@gkevinzheng gkevinzheng changed the title docs: Update dictConfig snippet to add line that applies the config docs: Update dictConfig snippet Apr 18, 2024
@gkevinzheng gkevinzheng merged commit 6264107 into main Apr 24, 2024
16 of 17 checks passed
@gkevinzheng gkevinzheng deleted the gkevinzheng-patch-1 branch April 24, 2024 15:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: logging Issues related to the googleapis/python-logging API. size: s Pull request size is small.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants