Skip to content

Update Python logging examples in documentation. #2206

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 5 commits into from
Mar 9, 2025

Conversation

cgoldberg
Copy link
Contributor

@cgoldberg cgoldberg commented Mar 3, 2025

User description

Description

This adds information to the logging docs in documentation/webdriver/troubleshooting/ for setting up log handlers in Python.

Fixes SeleniumHQ/selenium #15359

Motivation and Context

The examples were incomplete and this is necessary to show how to get log output in Python.

Types of changes

  • Change to the site (I have double-checked the Netlify deployment, and my changes look good)
  • Code example added (and I also added the example to all translated languages)
  • Improved translation
  • Added new translation (and I also added a notice to each document missing translation)

Checklist

  • I have read the contributing document.
  • I have used hugo to render the site/docs locally and I am sure it works.

PR Type

Documentation


Description

  • Added Python logging handler examples to documentation.

  • Updated logging examples in English, Japanese, Portuguese, and Chinese.

  • Improved clarity on setting up Python log handlers.


Changes walkthrough 📝

Relevant files
Documentation
logging.en.md
Add Python logging handler example in English documentation

website_and_docs/content/documentation/webdriver/troubleshooting/logging.en.md

  • Added example for setting up a Python logging handler.
  • Included StreamHandler and FileHandler usage for console logs.
  • +6/-0     
    logging.ja.md
    Add Python logging handler example in Japanese documentation

    website_and_docs/content/documentation/webdriver/troubleshooting/logging.ja.md

  • Added example for setting up a Python logging handler.
  • Included StreamHandler and FileHandler usage for console logs.
  • +6/-0     
    logging.pt-br.md
    Add Python logging handler example in Portuguese documentation

    website_and_docs/content/documentation/webdriver/troubleshooting/logging.pt-br.md

  • Added example for setting up a Python logging handler.
  • Included StreamHandler and FileHandler usage for console logs.
  • +6/-0     
    logging.zh-cn.md
    Add Python logging handler example in Chinese documentation

    website_and_docs/content/documentation/webdriver/troubleshooting/logging.zh-cn.md

  • Added example for setting up a Python logging handler.
  • Included StreamHandler and FileHandler usage for console logs.
  • +6/-0     

    Need help?
  • Type /help how to ... in the comments thread for any questions about Qodo Merge usage.
  • Check out the documentation for more information.
  • This adds information to the logging docs in
    `documentation/webdriver/troubleshooting/`` for setting up
    log handlers in Python. This is necessary to get log output.
    Copy link

    netlify bot commented Mar 3, 2025

    👷 Deploy request for selenium-dev pending review.

    Visit the deploys page to approve it

    Name Link
    🔨 Latest commit 01c7129

    Copy link
    Contributor

    qodo-merge-pro bot commented Mar 3, 2025

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 1 🔵⚪⚪⚪⚪
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Translation Missing

    The added Python logging example appears to be in English within the Chinese documentation file. This content should be translated to Chinese for consistency.

    You must also set a handler (`StreamHandler`, `FileHandler('/path/to/log')`, etc).
    For example, to see logs in the console, you can do this:
    ```py
    handler = logging.StreamHandler()
    logger.addHandler(handler)
    
    </details>
    
    </td></tr>
    </table>
    

    Copy link
    Contributor

    qodo-merge-pro bot commented Mar 3, 2025

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Impact
    General
    Add missing log level configuration

    Add log level configuration to the example to demonstrate proper logger setup.
    Without setting a log level, messages below WARNING won't be displayed.

    website_and_docs/content/documentation/webdriver/troubleshooting/logging.en.md [33-34]

     handler = logging.StreamHandler()
    +handler.setLevel(logging.INFO)  # Set desired log level
     logger.addHandler(handler)
    • Apply this suggestion
    Suggestion importance[1-10]: 8

    __

    Why: Setting the log level is crucial for proper logger functionality as without it, important messages below WARNING level won't be visible. This is essential for effective debugging and troubleshooting.

    Medium
    Add timestamp and level formatting

    Add a formatter to the handler to show timestamp and log level in the output,
    which is crucial for troubleshooting.

    website_and_docs/content/documentation/webdriver/troubleshooting/logging.en.md [33-34]

     handler = logging.StreamHandler()
    +formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
    +handler.setFormatter(formatter)
     logger.addHandler(handler)
    • Apply this suggestion
    Suggestion importance[1-10]: 7

    __

    Why: Adding a formatter with timestamp and log level significantly improves log readability and usefulness for debugging by providing crucial context for each log message.

    Medium
    • Update

    @cgoldberg
    Copy link
    Contributor Author

    @Delta456
    I updated my branch so it shows examples of both StreamHandler and FileHandler for console and file logging. Rather than showing the code block from test_logging.py like you suggested, I added the examples directly to the document... because the example in the test file gets log_path from a test fixture, which I thought might confuse users. My example shows explicitly setting the log_path value.

    Let me know what you think.

    @Delta456
    Copy link
    Member

    Delta456 commented Mar 6, 2025

    @Delta456 I updated my branch so it shows examples of both StreamHandler and FileHandler for console and file logging. Rather than showing the code block from test_logging.py like you suggested, I added the examples directly to the document... because the example in the test file gets log_path from a test fixture, which I thought might confuse users. My example shows explicitly setting the log_path value.

    Let me know what you think.

    This is a better way than what I originally proposed. Thanks!

    @cgoldberg
    Copy link
    Contributor Author

    cgoldberg commented Mar 8, 2025

    @Delta456 Do you have access to merge this? (I don't). If not, who needs to pull the trigger to land this in trunk?

    @Delta456
    Copy link
    Member

    Delta456 commented Mar 9, 2025

    @Delta456 Do you have access to merge this? (I don't). If not, who needs to pull the trigger to land this in trunk?

    I also don't have access to merge this. @harsha509 or any other TLC member can merge this.

    Copy link
    Member

    @harsha509 harsha509 left a comment

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    Thank you @cgoldberg !

    @harsha509 harsha509 merged commit e4f3470 into SeleniumHQ:trunk Mar 9, 2025
    3 checks passed
    selenium-ci added a commit that referenced this pull request Mar 9, 2025
    * Update Python logging examples in documentation.
    
    This adds information to the logging docs in
    `documentation/webdriver/troubleshooting/`` for setting up
    log handlers in Python. This is necessary to get log output.
    
    * Add file logging to Python logging examples
    
    ---------
    
    Co-authored-by: Sri Harsha <12621691+harsha509@users.noreply.github.com> e4f3470
    @cgoldberg cgoldberg deleted the python-log-examples branch March 22, 2025 04:24
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    [🐛 Bug]: Python logging not working correctly
    3 participants