Skip to content

migrate code from googleapis/python-logging#13844

Merged
iennae merged 227 commits intomainfrom
python-logging-migration
Feb 19, 2026
Merged

migrate code from googleapis/python-logging#13844
iennae merged 227 commits intomainfrom
python-logging-migration

Conversation

@chalmerlowe
Copy link
Contributor

Description

Fixes #

Note: Before submitting a pull request, please open an issue for discussion if you are not associated with Google.

Checklist

Jon Wayne Parrott and others added 30 commits October 30, 2020 17:57
Change-Id: I67e149dc43ebdb11144ac3839e062aa4668ebb2e
Change-Id: I866edcc956fda2265dd7af7b774336930ec6a151
Change-Id: Ieaf7237fc6f925daec46a07d2e81a452b841198a
* Add tests for quickstarts
* Update secrets
* Remove cloud config fixture

* Fix client secrets

* Fix bigtable instance
* Auto-update dependencies.

* xfail the error reporting test

* Fix lint
* Fix README rst links

* Update all READMEs
* Auto-update dependencies.

* Fix natural language samples

* Fix pubsub iam samples

* Fix language samples

* Fix bigquery samples
* Auto-update dependencies.

* Explicitly use latest bigtable client

Change-Id: Id71e9e768f020730e4ca9514a0d7ebaa794e7d9e

* Revert language update for now

Change-Id: I8867f154e9a5aae00d0047c9caf880e5e8f50c53

* Remove pdb. smh

Change-Id: I5ff905fadc026eebbcd45512d4e76e003e3b2b43
Change-Id: I6691c70912b1e1b5993e962a4827a846642feac3
* Auto-update dependencies.

* Fix storage notification poll sample

Change-Id: I6afbc79d15e050531555e4c8e51066996717a0f3

* Fix spanner samples

Change-Id: I40069222c60d57e8f3d3878167591af9130895cb

* Drop coverage because it's not useful

Change-Id: Iae399a7083d7866c3c7b9162d0de244fbff8b522

* Try again to fix flaky logging test

Change-Id: I6225c074701970c17c426677ef1935bb6d7e36b4
Change-Id: I03b5eaef8b17ac3dc3c0339fd2c7447bd3e11bd2
* Update Readme.rst to add Python setup guide

As requested in b/64770713.

This sample is linked in documentation https://cloud.google.com/bigtable/docs/scaling, and it would make more sense to update the guide here than in the documentation.

* Update README.rst

* Update README.rst

* Update README.rst

* Update README.rst

* Update README.rst

* Update install_deps.tmpl.rst

* Updated readmegen scripts and re-generated related README files

* Fixed the lint error
Change-Id: I0d420f3053f391fa225e4b8179e45fd1138f5c65
#1233)

* Add sample for standard library logging handler configuration

* Add handler.py to readme
* Auto-update dependencies.

* Update requirements.txt
gcf-owl-bot bot and others added 17 commits November 29, 2023 15:19
* chore(python): Add Python 3.12

Source-Link: googleapis/synthtool@af16e6d
Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:bacc3af03bff793a03add584537b36b5644342931ad989e3ba1171d3bd5399f5

* add trove classifier for python 3.12

* add python 3.12, and older, as a required check

---------

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
Co-authored-by: Anthonios Partheniou <partheniou@google.com>
* build: treat warnings as errors

* resolve warning Client.dataset is deprecated and will be removed in a future version

* See googleapis/python-logging#820

* address warning @pytest.yield_fixture is deprecated. Use @pytest.fixture instead; they are the same.

* filter warnings from grpcio

* revert

* update comment
Co-authored-by: Kevin Zheng <147537668+gkevinzheng@users.noreply.github.com>
* chore(deps): update all dependencies

* Update requirements-test.txt for Python 3.7 compatibility

---------

Co-authored-by: Kevin Zheng <147537668+gkevinzheng@users.noreply.github.com>
#848)

* docs: Added documentation for Django/Flask integrations and dictConfig

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

* Added product prefix to new snippet

* Added client setup in sample + link to settings in documentation

* Changed django links to point to `/stable/` links

---------

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
* chore(deps): update all dependencies

* pin pytest for python 3.7

---------

Co-authored-by: Anthonios Partheniou <partheniou@google.com>
* 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>
…ours in export_test.py (#925)

* chore: Running this to remove all sinks

* readd try block

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

* added timestamp to sink name

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

* Fixed regex string

* 🦉 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>
* chore(python): update dependencies in .kokoro/docker/docs

Source-Link: googleapis/synthtool@59171c8
Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:2ed982f884312e4883e01b5ab8af8b6935f0216a5a2d82928d273081fc3be562

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

* add constraints file for Python 3.13

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

* Remove obsolete release configs and script

---------

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
Co-authored-by: Anthonios Partheniou <partheniou@google.com>
… setup_logging (#971)

* docs: Added documentation on log_level and excluded_loggers params in
setup_logging

* Added product prefix to new region tags.
* test: Added cleanup of old sink storage buckets

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

* add list_buckets threshold

---------

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
Co-authored-by: Anthonios Partheniou <partheniou@google.com>
This PR adds python 3.14 support to the python-logging package.

Expanding off of Omair's work here:
googleapis/python-logging#1055

---------

Co-authored-by: ohmayr <omairn@google.com>
Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
Co-authored-by: Kevin Zheng <kevzheng@google.com>
Co-authored-by: Anthonios Partheniou <partheniou@google.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@chalmerlowe chalmerlowe requested review from a team as code owners February 19, 2026 15:04
@product-auto-label product-auto-label bot added the samples Issues that are directly related to samples. label Feb 19, 2026
@snippet-bot
Copy link

snippet-bot bot commented Feb 19, 2026

Here is the summary of possible violations 😱

Details

There are 35 possible violations for not having product prefix.

The end of the violation section. All the stuff below is FYI purposes only.


Here is the summary of changes.

You are about to add 53 region tags.

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

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @chalmerlowe, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This extensive pull request orchestrates a major update and migration of the Python samples for Google Cloud Logging. It systematically transitions the sample code to leverage the latest google-cloud client library, moving away from the older googleapis/python-logging structure. A significant portion of the changes involves the introduction of automatically generated code snippets for various Logging API services, ensuring comprehensive coverage and consistency. Furthermore, the PR modernizes the project's development and testing toolchain, updating numerous dependencies, enhancing documentation, and adding support for newer Python versions and advanced testing capabilities. This ensures the samples are up-to-date, maintainable, and aligned with current best practices.

Highlights

  • Comprehensive Migration: The pull request completes a significant migration of Cloud Logging Python samples from the legacy googleapis/python-logging to the modern google-cloud client library.
  • Automated Code Generation: A large suite of new generated samples has been introduced for ConfigServiceV2, LoggingServiceV2, and MetricsServiceV2 methods, covering both asynchronous and synchronous operations.
  • Dependency and Tooling Updates: All dependencies have been updated, and the development environment has been modernized with new noxfile configurations, including support for newer Python versions (up to 3.14), and integration of black and isort for code formatting.
  • Enhanced Documentation and Samples: New and updated documentation files, including README.rst.in templates, AUTHORING_GUIDE.md, and CONTRIBUTING.md redirects, ensure consistency and improved guidance. New samples for standard library logging handler configuration and Log Analytics features have also been added.
  • Improved Testing Infrastructure: Test files (*_test.py) have been added or updated for new samples, and the noxfile now supports pytest-xdist and pytest-parallel for concurrent testing, alongside cleanup fixtures for test resources.
Activity
  • No human activity (comments, reviews, progress) was provided in the context for this pull request.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This PR migrates a large number of logging samples and generated snippets. The changes are extensive, adding new samples for various logging features like sinks, metrics, and handlers, along with corresponding tests and configuration files. The new samples are a great addition. I've reviewed the code and found a few areas for improvement, mainly related to security best practices in the usage guide snippets and a minor bug in command-line argument parsing in another snippet.

# [START sink_bucket_permissions]
bucket.acl.reload() # API call
logs_group = bucket.acl.group("cloud-logs@google.com")
logs_group.grant_owner()
Copy link
Contributor

Choose a reason for hiding this comment

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

security-high high

The OWNER permission is overly permissive for exporting logs to a Cloud Storage bucket. The logging service account only requires WRITER permission to create log files. Granting OWNER permission violates the principle of least privilege as it allows the service account to manage bucket properties and even delete the bucket. Please use grant_writer() instead.

Suggested change
logs_group.grant_owner()
logs_group.grant_writer()

topic = client.create_topic(request={"name": topic_path})

policy = client.get_iam_policy(request={"resource": topic_path}) # API call
policy.bindings.add(role="roles/owner", members=["group:cloud-logs@google.com"])
Copy link
Contributor

Choose a reason for hiding this comment

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

security-high high

The roles/owner IAM role is overly permissive for this use case. To allow the logging service account to publish messages to the Pub/Sub topic, the roles/pubsub.publisher role is sufficient and follows the principle of least privilege.

Suggested change
policy.bindings.add(role="roles/owner", members=["group:cloud-logs@google.com"])
policy.bindings.add(role="roles/pubsub.publisher", members=["group:cloud-logs@google.com"])

parser = argparse.ArgumentParser(
description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter
)
parser.add_argument("logger_name", help="Logger name", default="example_log")
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The default value for a positional argparse argument is only used when nargs is set to ? or *. As it is, logger_name is a required argument, and the provided default "example_log" will never be used. To make the argument optional with a default value, you should add nargs="?".

Suggested change
parser.add_argument("logger_name", help="Logger name", default="example_log")
parser.add_argument("logger_name", help="Logger name", nargs="?", default="example_log")

@chalmerlowe chalmerlowe force-pushed the python-logging-migration branch from 39ab60b to 2b16cce Compare February 19, 2026 18:25
removing noxfile to avoid conflicts.
@chalmerlowe
Copy link
Contributor Author

Note to self:

  • Header check error shows multiple refs to Google Inc.
  • Kokoro CI - Lint error is misordered imports
  • Kokoro CI - Python 3.14 error is based on the fact that we don't have a protobuf override for 3.14 in the noxfile.
  • snippet-bot check error shows region tags are missing the proper prefix.

@iennae iennae merged commit 1dcb59b into main Feb 19, 2026
10 of 14 checks passed
@iennae iennae deleted the python-logging-migration branch February 19, 2026 19:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

samples Issues that are directly related to samples.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Comments