You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pekko.apache.org by fa...@apache.org on 2026/09/11 21:06:14 UTC
(pekko-connectors) branch main updated: AWS SPI Pekko HTTP, Testkit: use parameterized slf4j logging (#1940)
This is an automated email from the ASF dual-hosted git repository.
pjfanning pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/pekko-connectors.git
The following commit(s) were added to refs/heads/main by this push:
new 6431bdac5 AWS SPI Pekko HTTP, Testkit: use parameterized slf4j logging (#1940)
6431bdac5 is described below
commit 6431bdac5414464e57de35123e9c4ee7f2c5cf66
Author: PJ Fanning <pj...@users.noreply.github.com>
AuthorDate: Fri Sep 11 22:06:07 2026 +0100
AWS SPI Pekko HTTP, Testkit: use parameterized slf4j logging (#1940)
Motivation:
Several slf4j log calls in main sources built their message with an
s-interpolator, so the string was concatenated even when the level was
disabled. slf4j can defer that formatting to the point where it knows
the event will actually be emitted.
Modification:
Replaced the interpolated messages with `{}` placeholders and argument
lists in PekkoHttpClient.tryCreateCustomContentType, LogCapturing and
LogCapturingJunit4. Log output is unchanged.
Result:
No message is formatted unless the level is enabled; the debug call in
tryCreateCustomContentType no longer builds a string on every request
when debug logging is off.
Tests:
- sbt "aws-spi-pekko-http/compile" "s3/compile" "testkit/compile" / pass
- sbt -batch "++3.3.8" "aws-spi-pekko-http/compile" "s3/compile" "testkit/compile" / pass
- scalafmt --list on changed files / clean
- PekkoHttpClientSpec gains a directional test asserting the debug line
renders with the argument substituted; not executed locally, left to CI
References:
None - follow-up cleanup of slf4j usage in main sources
---
.../stream/connectors/awsspi/PekkoHttpClient.scala | 2 +-
.../connectors/awsspi/PekkoHttpClientSpec.scala | 24 ++++++++++++++++++++++
.../testkit/javadsl/LogCapturingJunit4.scala | 6 ++++--
.../connectors/testkit/scaladsl/LogCapturing.scala | 4 ++--
4 files changed, 31 insertions(+), 5 deletions(-)
diff --git a/aws-spi-pekko-http/src/main/scala/org/apache/pekko/stream/connectors/awsspi/PekkoHttpClient.scala b/aws-spi-pekko-http/src/main/scala/org/apache/pekko/stream/connectors/awsspi/PekkoHttpClient.scala
index cb8d25011..a1dc973d0 100644
--- a/aws-spi-pekko-http/src/main/scala/org/apache/pekko/stream/connectors/awsspi/PekkoHttpClient.scala
+++ b/aws-spi-pekko-http/src/main/scala/org/apache/pekko/stream/connectors/awsspi/PekkoHttpClient.scala
@@ -167,7 +167,7 @@ object PekkoHttpClient {
}
private[awsspi] def tryCreateCustomContentType(contentTypeStr: String): ContentType = {
- logger.debug(s"Try to parse content type from $contentTypeStr")
+ logger.debug("Try to parse content type from {}", contentTypeStr)
val mainAndsubType = contentTypeStr.split('/')
if (mainAndsubType.length == 2)
ContentType(MediaType.customBinary(mainAndsubType(0), mainAndsubType(1), Compressible))
diff --git a/aws-spi-pekko-http/src/test/scala/org/apache/pekko/stream/connectors/awsspi/PekkoHttpClientSpec.scala b/aws-spi-pekko-http/src/test/scala/org/apache/pekko/stream/connectors/awsspi/PekkoHttpClientSpec.scala
index 1811285f4..d07b892c3 100644
--- a/aws-spi-pekko-http/src/test/scala/org/apache/pekko/stream/connectors/awsspi/PekkoHttpClientSpec.scala
+++ b/aws-spi-pekko-http/src/test/scala/org/apache/pekko/stream/connectors/awsspi/PekkoHttpClientSpec.scala
@@ -19,6 +19,9 @@ package org.apache.pekko.stream.connectors.awsspi
import java.util.Collections
import java.nio.ByteBuffer
+import ch.qos.logback.classic.{ Level, Logger => LogbackLogger }
+import ch.qos.logback.classic.spi.ILoggingEvent
+import ch.qos.logback.core.read.ListAppender
import com.typesafe.config.ConfigFactory
import org.apache.pekko
@@ -34,6 +37,7 @@ import software.amazon.awssdk.http.async.SdkHttpContentPublisher
import software.amazon.awssdk.utils.AttributeMap
import scala.concurrent.duration._
+import scala.jdk.CollectionConverters._
import scala.jdk.DurationConverters._
class PekkoHttpClientSpec extends AnyWordSpec with Matchers with OptionValues {
@@ -46,6 +50,26 @@ class PekkoHttpClientSpec extends AnyWordSpec with Matchers with OptionValues {
contentType.mediaType should be(MediaTypes.`application/xml`)
}
+ "log the content type it parses with the argument substituted into the message" in {
+ val contentTypeStr = "application/xml"
+ val logbackLogger = PekkoHttpClient.logger.asInstanceOf[LogbackLogger]
+ val appender = new ListAppender[ILoggingEvent]
+ val previousLevel = logbackLogger.getLevel
+ appender.start()
+ logbackLogger.addAppender(appender)
+ logbackLogger.setLevel(Level.DEBUG)
+ try {
+ PekkoHttpClient.tryCreateCustomContentType(contentTypeStr)
+ } finally {
+ logbackLogger.setLevel(previousLevel)
+ logbackLogger.detachAppender(appender)
+ appender.stop()
+ }
+
+ val messages = appender.list.asScala.map(_.getFormattedMessage).toList
+ messages should contain(s"Try to parse content type from $contentTypeStr")
+ }
+
"remove 'ContentType' return 'ContentLength' separate from sdk headers" in {
val headers = new java.util.HashMap[String, java.util.List[String]]
headers.put("Content-Type", Collections.singletonList("application/xml"))
diff --git a/testkit/src/main/scala/org/apache/pekko/stream/connectors/testkit/javadsl/LogCapturingJunit4.scala b/testkit/src/main/scala/org/apache/pekko/stream/connectors/testkit/javadsl/LogCapturingJunit4.scala
index e771e9084..a4ace73d5 100644
--- a/testkit/src/main/scala/org/apache/pekko/stream/connectors/testkit/javadsl/LogCapturingJunit4.scala
+++ b/testkit/src/main/scala/org/apache/pekko/stream/connectors/testkit/javadsl/LogCapturingJunit4.scala
@@ -56,10 +56,12 @@ final class LogCapturingJunit4 extends TestRule {
new Statement {
override def evaluate(): Unit = {
try {
- myLogger.info(s"Logging started for test [${description.getClassName}: ${description.getMethodName}]")
+ myLogger.info("Logging started for test [{}: {}]", description.getClassName, description.getMethodName)
base.evaluate()
myLogger.info(
- s"Logging finished for test [${description.getClassName}: ${description.getMethodName}] that was successful")
+ "Logging finished for test [{}: {}] that was successful",
+ description.getClassName,
+ description.getMethodName)
} catch {
case NonFatal(e) =>
println(
diff --git a/testkit/src/main/scala/org/apache/pekko/stream/connectors/testkit/scaladsl/LogCapturing.scala b/testkit/src/main/scala/org/apache/pekko/stream/connectors/testkit/scaladsl/LogCapturing.scala
index 5af8db8cd..9cd4a2ab1 100644
--- a/testkit/src/main/scala/org/apache/pekko/stream/connectors/testkit/scaladsl/LogCapturing.scala
+++ b/testkit/src/main/scala/org/apache/pekko/stream/connectors/testkit/scaladsl/LogCapturing.scala
@@ -65,11 +65,11 @@ trait LogCapturing extends BeforeAndAfterAll { self: TestSuite =>
abstract override def withFixture(test: NoArgTest): Outcome = {
sourceActorSystem.foreach(MDC.put("sourceActorSystem", _))
- myLogger.info(s"Logging started for test [${self.getClass.getName}: ${test.name}]")
+ myLogger.info("Logging started for test [{}: {}]", self.getClass.getName, test.name)
sourceActorSystem.foreach(_ => MDC.remove("sourceActorSystem"))
val res = test()
sourceActorSystem.foreach(MDC.put("sourceActorSystem", _))
- myLogger.info(s"Logging finished for test [${self.getClass.getName}: ${test.name}] that [$res]")
+ myLogger.info("Logging finished for test [{}: {}] that [{}]", self.getClass.getName, test.name, res)
sourceActorSystem.foreach(_ => MDC.remove("sourceActorSystem"))
if (!(res.isSucceeded || res.isPending)) {
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pekko.apache.org
For additional commands, e-mail: commits-help@pekko.apache.org