Skip to content

chore(jdbc): add console logs during tests#4130

Merged
logachev merged 3 commits intomainfrom
kirl/test_logs
Mar 6, 2026
Merged

chore(jdbc): add console logs during tests#4130
logachev merged 3 commits intomainfrom
kirl/test_logs

Conversation

@logachev
Copy link
Contributor

@logachev logachev commented Mar 5, 2026

Enable logging to console during test runs.

The idea behind this change is "If we can't figure out why test is failing with logs-only, we need more logs". Right now always have to run test with a debugger to really figure out what's wrong.

@logachev logachev requested review from a team as code owners March 5, 2026 00:57
@product-auto-label product-auto-label bot added size: s Pull request size is small. api: bigquery Issues related to the googleapis/java-bigquery API. labels Mar 5, 2026
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, 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 pull request enhances the debugging experience during test runs by enabling console logging. By setting a system property during Maven test execution, the logging framework is configured to output logs directly to the console, providing immediate visibility into test behavior without requiring a debugger. This change aims to streamline the process of identifying and resolving test failures.

Highlights

  • Enabled Test Logging: Configured Maven Surefire and Failsafe plugins to set a JDBC_TESTS system property during test execution, signaling when tests are running.
  • Conditional Console Output: Introduced a mechanism in BigQueryJdbcRootLogger to detect test runs via the JDBC_TESTS property and conditionally add a ConsoleHandler to the main logger, directing log output to the console during tests.
  • Refined Handler Management: Updated the logger's handler management logic to prevent the removal of the ConsoleHandler during test runs, ensuring continuous console logging when JDBC_TESTS is active, and adjusted the loop to process all handlers.
Changelog
  • google-cloud-bigquery-jdbc/pom.xml
    • Added JDBC_TESTS system property to the maven-surefire-plugin configuration.
    • Added JDBC_TESTS system property to the maven-failsafe-plugin configuration.
  • google-cloud-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryJdbcRootLogger.java
    • Introduced a static boolean isTest field, initialized by checking the JDBC_TESTS system property.
    • Added a conditional block in the static initializer to add a ConsoleHandler to the logger if isTest is true.
    • Modified the setHandler method to conditionally remove ConsoleHandler only when isTest is false, and adjusted the loop to process all handlers without breaking early.
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 pull request aims to add console logging during test runs, which is a helpful addition for debugging. The changes in pom.xml to enable this are correct. In BigQueryJdbcRootLogger.java, I've identified a couple of areas for improvement. Firstly, the log level for the new console handler is set to SEVERE, which is highly restrictive and may not align with the goal of getting more detailed logs; I've suggested a more permissive level. Secondly, a break statement was removed from a loop, which I recommend restoring for efficiency and to prevent potential subtle issues. My detailed feedback is in the comments below.

storageLogger.setUseParentHandlers(true);
if (isTest) {
ConsoleHandler consoleHandler = new ConsoleHandler();
consoleHandler.setLevel(Level.SEVERE);
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 console handler's level is set to SEVERE, which will only show logs of level SEVERE or higher. The pull request description states, "If we can't figure out why test is failing with logs-only, we need more logs", which suggests more verbose logging is desired. Level.SEVERE is very restrictive. Consider using a less restrictive level like Level.INFO to capture more log details during test runs.

Suggested change
consoleHandler.setLevel(Level.SEVERE);
consoleHandler.setLevel(Level.INFO);

Comment on lines +125 to 127
} else if (h instanceof FileHandler) {
fileHandler = h;
break;
}
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 break statement was removed from this block. It should be restored to avoid iterating unnecessarily after the FileHandler is found. This also prevents a potential change in behavior from using the first found handler to the last one, in the unlikely case of multiple FileHandler instances.

      } else if (h instanceof FileHandler) {
        fileHandler = h;
        break;
      }

@logachev logachev added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Mar 6, 2026
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Mar 6, 2026
@logachev logachev merged commit ecbf402 into main Mar 6, 2026
26 checks passed
@logachev logachev deleted the kirl/test_logs branch March 6, 2026 22:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: bigquery Issues related to the googleapis/java-bigquery API. size: s Pull request size is small.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants