Repository: googleapis/java-storage
Pull request #2946 (2025-02-21 23:53:27)

test: add slf4j and logback config for tests


Patch:
diff --git a/README.md b/README.md
index 6ca40a1a..e44bc8f6 100644
--- a/README.md
+++ b/README.md
@@ -59,7 +59,7 @@ If you are using Maven without the BOM, add this to your dependencies:
 If you are using Gradle 5.x or later, add this to your dependencies:
 
 ```Groovy
-implementation platform('com.google.cloud:libraries-bom:26.54.0')
+implementation platform('com.google.cloud:libraries-bom:26.55.0')
 
 implementation 'com.google.cloud:google-cloud-storage'
 ```
diff --git a/generation_config.yaml b/generation_config.yaml
index 0268d85f..c288bdd2 100644
--- a/generation_config.yaml
+++ b/generation_config.yaml
@@ -1,6 +1,6 @@
 gapic_generator_version: 2.53.0
-googleapis_commitish: a003cab30e2a263e16e9252256041f8934f40e2c
-libraries_bom_version: 26.54.0
+googleapis_commitish: 3b2e8657f0bef4d9638f2957ed9d988adc65427c
+libraries_bom_version: 26.55.0
 libraries:
   - api_shortname: storage
     name_pretty: Cloud Storage
diff --git a/google-cloud-storage/pom.xml b/google-cloud-storage/pom.xml
index ec307a7d..c37a0008 100644
--- a/google-cloud-storage/pom.xml
+++ b/google-cloud-storage/pom.xml
@@ -334,6 +334,18 @@
       <version>4.8.179</version>
       <scope>test</scope>
     </dependency>
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>jul-to-slf4j</artifactId>
+      <version>2.0.16</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>ch.qos.logback</groupId>
+      <artifactId>logback-classic</artifactId>
+      <version>1.3.15</version>
+      <scope>test</scope>
+    </dependency>
   </dependencies>
 
   <build>
@@ -386,6 +398,22 @@
               -->
               <dependency>io.opentelemetry:opentelemetry-sdk-extension-autoconfigure-spi</dependency>
               <dependency>io.opentelemetry.semconv:opentelemetry-semconv</dependency>
+              <!--
+              com.google.cloud.opentelemetry:exporter-metrics depends on slf4j
+              We are also using slf4j and logback in our test scope
+              list things out here to appease the dependency checker that gets confused like the following
+
+              [ERROR] Used undeclared dependencies found:
+              [ERROR]    org.slf4j:slf4j-api:jar:2.0.16:compile
+              [ERROR] Unused declared dependencies found:
+              [ERROR]    org.slf4j:jul-to-slf4j:jar:2.0.16:test
+              [ERROR]    ch.qos.logback:logback-classic:jar:1.3.15:test
+              [ERROR] Non-test scoped test only dependencies found:
+              [ERROR]    org.slf4j:slf4j-api:jar:2.0.16:compile
+              -->
+              <dependency>org.slf4j:slf4j-api</dependency>
+              <dependency>org.slf4j:jul-to-slf4j</dependency>
+              <dependency>ch.qos.logback:logback-classic</dependency>
             </ignoredDependencies>
           </configuration>
         </plugin>
diff --git a/pom.xml b/pom.xml
index cf4e8e8b..7dc31d20 100644
--- a/pom.xml
+++ b/pom.xml
@@ -69,7 +69,7 @@
       <dependency>
         <groupId>org.junit</groupId>
         <artifactId>junit-bom</artifactId>
-        <version>5.11.4</version>
+        <version>5.12.0</version>
         <type>pom</type>
         <scope>import</scope>
       </dependency>
diff --git a/samples/snippets/pom.xml b/samples/snippets/pom.xml
index 7a517595..25f002fa 100644
--- a/samples/snippets/pom.xml
+++ b/samples/snippets/pom.xml
@@ -31,7 +31,7 @@
       <dependency>
         <groupId>com.google.cloud</groupId>
         <artifactId>libraries-bom</artifactId>
-        <version>26.54.0</version>
+        <version>26.55.0</version>
         <type>pom</type>
         <scope>import</scope>
       </dependency>


Test patch:
diff --git a/google-cloud-storage/src/test/java/com/google/cloud/storage/it/runner/StorageITRunner.java b/google-cloud-storage/src/test/java/com/google/cloud/storage/it/runner/StorageITRunner.java
index 814c5da6..d99df4b8 100644
--- a/google-cloud-storage/src/test/java/com/google/cloud/storage/it/runner/StorageITRunner.java
+++ b/google-cloud-storage/src/test/java/com/google/cloud/storage/it/runner/StorageITRunner.java
@@ -42,6 +42,8 @@ import org.junit.runners.Suite;
 import org.junit.runners.model.FrameworkField;
 import org.junit.runners.model.InitializationError;
 import org.junit.runners.model.TestClass;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * Storage custom runner which will handle {@link CrossRun}, {@link SingleBackend}, {@link
@@ -53,6 +55,12 @@ import org.junit.runners.model.TestClass;
  * @see org.junit.runners.BlockJUnit4ClassRunner
  */
 public final class StorageITRunner extends Suite {
+  static {
+    org.slf4j.bridge.SLF4JBridgeHandler.removeHandlersForRootLogger();
+    org.slf4j.bridge.SLF4JBridgeHandler.install();
+  }
+
+  private static final Logger LOGGER = LoggerFactory.getLogger(StorageITRunner.class);
 
   private final Lock childrenLock = new ReentrantLock();
   private volatile ImmutableList<Runner> filteredChildren = null;
@@ -67,6 +75,7 @@ public final class StorageITRunner extends Suite {
 
   @Override
   public void run(RunNotifier notifier) {
+    LOGGER.debug("run(notifier : {})", notifier);
     super.run(new RunNotifierUnion(notifier, Registry.getInstance()));
   }
 
diff --git a/google-cloud-storage/src/test/resources/logback.xml b/google-cloud-storage/src/test/resources/logback.xml
new file mode 100644
index 00000000..e97103c9
--- /dev/null
+++ b/google-cloud-storage/src/test/resources/logback.xml
@@ -0,0 +1,93 @@
+<!--
+  ~ Copyright 2025 Google LLC
+  ~
+  ~ Licensed under the Apache License, Version 2.0 (the "License");
+  ~ you may not use this file except in compliance with the License.
+  ~ You may obtain a copy of the License at
+  ~
+  ~       http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing, software
+  ~ distributed under the License is distributed on an "AS IS" BASIS,
+  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  ~ See the License for the specific language governing permissions and
+  ~ limitations under the License.
+  -->
+
+<configuration>
+  <contextListener class="ch.qos.logback.classic.jul.LevelChangePropagator">
+    <resetJUL>true</resetJUL>
+  </contextListener>
+  <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
+    <encoder>
+      <pattern>%date %-5.5level [%-24.24thread] %-45.45logger{45} - %message%n</pattern>
+    </encoder>
+  </appender>
+  <appender name="NOEXCEPTION" class="ch.qos.logback.core.ConsoleAppender">
+    <encoder>
+      <pattern>%date %-5.5level [%-24.24thread] %-45.45logger{45} - %message%nopex%n</pattern>
+    </encoder>
+  </appender>
+  <logger name="com.google.auth.oauth2.ComputeEngineCredentials" level="info"/>
+  <logger name="io.opencensus" level="info"/>
+  <logger name="io.grpc.ChannelLogger" level="info"/>
+  <!-- Context logs an exception when it's not able to find things, so suppress it's exception -->
+  <logger name="io.grpc.Context" level="info" additivity="false">
+    <appender-ref ref="NOEXCEPTION"/>
+  </logger>
+  <logger name="io.grpc.LoadBalancerRegistry" level="warn"/>
+  <logger name="io.grpc.NameResolverRegistry" level="warn"/>
+  <!--
+  GrpclbNameResolver logs an exception with several of it's messages that aren't
+  useful when you're only interested in the traffic
+  -->
+  <logger name="io.grpc.grpclb.GrpclbNameResolver" level="info" additivity="false">
+    <appender-ref ref="NOEXCEPTION"/>
+  </logger>
+  <logger name="io.grpc.ManagedChannelRegistry" level="info" additivity="false">
+    <appender-ref ref="NOEXCEPTION"/>
+  </logger>
+  <logger name="io.grpc.internal.ManagedChannelImplBuilder" level="info" additivity="false">
+    <appender-ref ref="NOEXCEPTION"/>
+  </logger>
+  <logger name="io.grpc.internal.AbstractManagedChannelImplBuilder" level="warn"/>
+  <logger name="io.grpc.internal.DnsNameResolver" level="warn"/>
+  <!--
+  netty initialization and event loop management appenders,
+  not necessarily what is desired when debugging requests
+  -->
+  <logger name="io.grpc.netty.shaded.io.grpc.netty" level="warn"/>
+  <logger name="io.grpc.netty.shaded.io.netty" level="warn"/>
+  <logger name="io.grpc.netty.shaded.io.netty.buffer" level="warn"/>
+  <logger name="io.grpc.netty.shaded.io.netty.channel.DefaultChannelId" level="warn"/>
+  <logger name="io.grpc.netty.shaded.io.netty.channel.MultithreadEventLoopGroup" level="warn"/>
+  <logger name="io.grpc.netty.shaded.io.netty.handler.ssl" level="warn"/>
+  <logger name="io.grpc.netty.shaded.io.netty.util.NetUtil" level="warn"/>
+  <logger name="io.grpc.netty.shaded.io.netty.util.Recycler" level="warn"/>
+  <logger name="io.grpc.netty.shaded.io.netty.util.ResourceLeakDetector" level="warn"/>
+  <logger name="io.grpc.netty.shaded.io.netty.util.ResourceLeakDetectorFactory" level="warn"/>
+  <logger name="io.grpc.netty.shaded.io.netty.util.internal.CleanerJava6" level="warn"/>
+  <logger name="io.grpc.netty.shaded.io.netty.util.internal.InternalThreadLocalMap" level="warn"/>
+  <logger name="io.grpc.netty.shaded.io.netty.util.internal.NativeLibraryLoader" level="warn"/>
+  <logger name="io.grpc.netty.shaded.io.netty.util.internal.PlatformDependent" level="warn"/>
+  <logger name="io.grpc.netty.shaded.io.netty.util.internal.PlatformDependent0" level="warn"/>
+  <logger name="io.perfmark.PerfMark" level="warn"/>
+  <!--
+  jdk11 appender which includes lots of details about ssl cypher suites
+  -->
+  <logger name="jdk.event.security" level="warn"/>
+  <!-- http request logging -->
+  <logger name="sun.net.www.protocol.http.HttpURLConnection" level="warn"/>
+  <logger name="com.google.api.client.http.HttpTransport" level="debug"/>
+  <logger name="com.google.cloud.storage.it.GrpcPlainRequestLoggingInterceptor" level="trace"/>
+  <!-- grpc netty traffic logging -->
+  <!--<logger name="io.grpc.netty.shaded.io.netty.handler.ssl.SslHandler" level="debug"/>-->
+  <!--<logger name="io.grpc.netty.shaded.io.grpc.netty.NettyClientHandler" level="debug"/>-->
+
+  <logger name="com.google.cloud.storage" level="info"/>
+  <logger name="com.google.cloud.storage.it" level="warn"/>
+
+  <root level="info">
+    <appender-ref ref="STDOUT"/>
+  </root>
+</configuration>