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-http.git


The following commit(s) were added to refs/heads/main by this push:
     new 608d1e790 Replace Scala string interpolation in log calls with lazy {} 
placeholder format (#1050)
608d1e790 is described below

commit 608d1e790b84283149483ef22a1317b206625a44
Author: PJ Fanning <[email protected]>
AuthorDate: Sun May 31 23:28:52 2026 +0100

    Replace Scala string interpolation in log calls with lazy {} placeholder 
format (#1050)
    
    * Replace string interpolation in log calls with {} placeholders
    
    * Guard non-trivial log.info params with isInfoEnabled check in 
PersistentConnection
    
    * Update PersistentConnection.scala
    
    ---------
    
    Co-authored-by: copilot-swe-agent[bot] 
<[email protected]>
---
 .../docs/http/scaladsl/HttpClientDecodingExampleSpec.scala   |  4 ++--
 .../docs/http/scaladsl/HttpServerWithActorInteraction.scala  |  2 +-
 .../pekko/http/impl/engine/client/HttpsProxyGraphStage.scala |  2 +-
 .../impl/engine/client/OutgoingConnectionBlueprint.scala     |  2 +-
 .../http/impl/engine/client/pool/NewHostConnectionPool.scala |  2 +-
 .../http/impl/engine/http2/client/PersistentConnection.scala | 12 +++++++-----
 .../pekko/http/impl/engine/parsing/HttpHeaderParser.scala    |  4 ++--
 .../scala/org/apache/pekko/http/impl/util/StreamUtils.scala  |  4 ++--
 .../main/scala/org/apache/pekko/http/impl/util/package.scala |  2 +-
 .../http/impl/engine/client/HostConnectionPoolSpec.scala     |  2 +-
 .../org/apache/pekko/http/scaladsl/ClientServerSpec.scala    |  2 +-
 .../apache/pekko/http/scaladsl/GracefulTerminationSpec.scala |  2 +-
 .../server/DontLeakActorsOnFailingConnectionSpecs.scala      |  4 ++--
 .../server/directives/FileAndResourceDirectives.scala        |  4 ++--
 .../pekko/http/impl/engine/http2/H2SpecIntegrationSpec.scala |  2 +-
 15 files changed, 26 insertions(+), 24 deletions(-)

diff --git 
a/docs/src/test/scala/docs/http/scaladsl/HttpClientDecodingExampleSpec.scala 
b/docs/src/test/scala/docs/http/scaladsl/HttpClientDecodingExampleSpec.scala
index c8b1aa274..c1429240b 100644
--- a/docs/src/test/scala/docs/http/scaladsl/HttpClientDecodingExampleSpec.scala
+++ b/docs/src/test/scala/docs/http/scaladsl/HttpClientDecodingExampleSpec.scala
@@ -50,7 +50,7 @@ class HttpClientDecodingExampleSpec extends PekkoSpec with 
CompileOnlySpec with
         case HttpEncodings.identity =>
           Coders.NoCoding
         case other =>
-          log.warning(s"Unknown encoding [$other], not decoding")
+          log.warning("Unknown encoding [{}], not decoding", other)
           Coders.NoCoding
       }
 
@@ -61,7 +61,7 @@ class HttpClientDecodingExampleSpec extends PekkoSpec with 
CompileOnlySpec with
       Future.traverse(requests)(http.singleRequest(_).map(decodeResponse))
 
     futureResponses.futureValue.foreach { resp =>
-      system.log.info(s"response is ${resp.toStrict(1.second).futureValue}")
+      system.log.info("response is {}", resp.toStrict(1.second).futureValue)
     }
 
     system.terminate()
diff --git 
a/docs/src/test/scala/docs/http/scaladsl/HttpServerWithActorInteraction.scala 
b/docs/src/test/scala/docs/http/scaladsl/HttpServerWithActorInteraction.scala
index 1c51fc7fd..a893f6af5 100644
--- 
a/docs/src/test/scala/docs/http/scaladsl/HttpServerWithActorInteraction.scala
+++ 
b/docs/src/test/scala/docs/http/scaladsl/HttpServerWithActorInteraction.scala
@@ -45,7 +45,7 @@ object HttpServerWithActorInteraction {
 
     def apply(bids: List[Bid]): Behaviors.Receive[Message] = Behaviors.receive 
{
       case (ctx, bid @ Bid(userId, offer)) =>
-        ctx.log.info(s"Bid complete: $userId, $offer")
+        ctx.log.info("Bid complete: {}, {}", userId, offer)
         apply(bids :+ bid)
       case (_, GetBids(replyTo)) =>
         replyTo ! Bids(bids)
diff --git 
a/http-core/src/main/scala/org/apache/pekko/http/impl/engine/client/HttpsProxyGraphStage.scala
 
b/http-core/src/main/scala/org/apache/pekko/http/impl/engine/client/HttpsProxyGraphStage.scala
index cf7694a82..45f5c2f17 100644
--- 
a/http-core/src/main/scala/org/apache/pekko/http/impl/engine/client/HttpsProxyGraphStage.scala
+++ 
b/http-core/src/main/scala/org/apache/pekko/http/impl/engine/client/HttpsProxyGraphStage.scala
@@ -150,7 +150,7 @@ private final class HttpsProxyGraphStage(
                     }
                     parser.onUpstreamFinish()
 
-                    log.debug(s"HTTP(S) proxy connection to {}:{} established. 
Now forwarding data.", targetHostName,
+                    log.debug("HTTP(S) proxy connection to {}:{} established. 
Now forwarding data.", targetHostName,
                       targetPort)
 
                     state = Connected
diff --git 
a/http-core/src/main/scala/org/apache/pekko/http/impl/engine/client/OutgoingConnectionBlueprint.scala
 
b/http-core/src/main/scala/org/apache/pekko/http/impl/engine/client/OutgoingConnectionBlueprint.scala
index 61cc26a97..589c8034d 100644
--- 
a/http-core/src/main/scala/org/apache/pekko/http/impl/engine/client/OutgoingConnectionBlueprint.scala
+++ 
b/http-core/src/main/scala/org/apache/pekko/http/impl/engine/client/OutgoingConnectionBlueprint.scala
@@ -107,7 +107,7 @@ private[http] object OutgoingConnectionBlueprint {
       val terminationFanout = b.add(Broadcast[HttpResponse](2))
 
       val logger =
-        b.add(Flow[ByteString].mapError { case t => log.debug(s"Outgoing 
request stream error {}", t); t }.named(
+        b.add(Flow[ByteString].mapError { case t => log.debug("Outgoing 
request stream error {}", t); t }.named(
           "errorLogger"))
       val wrapTls = b.add(Flow[ByteString].map(SendBytes(_)))
 
diff --git 
a/http-core/src/main/scala/org/apache/pekko/http/impl/engine/client/pool/NewHostConnectionPool.scala
 
b/http-core/src/main/scala/org/apache/pekko/http/impl/engine/client/pool/NewHostConnectionPool.scala
index d5d4a052a..98ec1e7ec 100644
--- 
a/http-core/src/main/scala/org/apache/pekko/http/impl/engine/client/pool/NewHostConnectionPool.scala
+++ 
b/http-core/src/main/scala/org/apache/pekko/http/impl/engine/client/pool/NewHostConnectionPool.scala
@@ -629,7 +629,7 @@ private[client] object NewHostConnectionPool {
         }
         override def postStop(): Unit = {
           slots.foreach(_.shutdown())
-          log.debug(s"Pool stopped")
+          log.debug("Pool stopped")
         }
 
         private def willClose(response: HttpResponse): Boolean =
diff --git 
a/http-core/src/main/scala/org/apache/pekko/http/impl/engine/http2/client/PersistentConnection.scala
 
b/http-core/src/main/scala/org/apache/pekko/http/impl/engine/http2/client/PersistentConnection.scala
index f4a9bbe21..6af316cc5 100644
--- 
a/http-core/src/main/scala/org/apache/pekko/http/impl/engine/http2/client/PersistentConnection.scala
+++ 
b/http-core/src/main/scala/org/apache/pekko/http/impl/engine/http2/client/PersistentConnection.scala
@@ -154,8 +154,9 @@ private[http2] object PersistentConnection {
             } else {
               setHandler(requestIn, Unconnected)
               if (baseEmbargo == Duration.Zero) {
-                log.info(s"Connection attempt failed: ${cause.getMessage}. 
Trying to connect again${connectsLeft.map(
-                    n => s" ($n attempts left)").getOrElse("")}.")
+                if (log.isInfoEnabled)
+                  log.info("Connection attempt failed: {}. Trying to connect 
again{}.", cause.getMessage,
+                    connectsLeft.map(n => s" ($n attempts 
left)").getOrElse(""))
                 connect(connectsLeft, Duration.Zero)
               } else {
                 val embargo = lastEmbargo match {
@@ -165,9 +166,10 @@ private[http2] object PersistentConnection {
                 val minMillis = embargo.toMillis
                 val maxMillis = minMillis * 2
                 val backoff = ThreadLocalRandom.current().nextLong(minMillis, 
maxMillis).millis
-                log.info(
-                  s"Connection attempt failed: ${cause.getMessage}. Trying to 
connect again after backoff ${PrettyDuration.format(
-                      backoff)} ${connectsLeft.map(n => s" ($n attempts 
left)").getOrElse("")}.")
+                if (log.isInfoEnabled)
+                  log.info("Connection attempt failed: {}. Trying to connect 
again after backoff {} {}.",
+                    cause.getMessage, PrettyDuration.format(backoff),
+                    connectsLeft.map(n => s" ($n attempts 
left)").getOrElse(""))
                 scheduleOnce(EmbargoEnded(connectsLeft, embargo), backoff)
               }
             }
diff --git 
a/http-core/src/main/scala/org/apache/pekko/http/impl/engine/parsing/HttpHeaderParser.scala
 
b/http-core/src/main/scala/org/apache/pekko/http/impl/engine/parsing/HttpHeaderParser.scala
index 7bfc0dc25..2815ff9d0 100644
--- 
a/http-core/src/main/scala/org/apache/pekko/http/impl/engine/parsing/HttpHeaderParser.scala
+++ 
b/http-core/src/main/scala/org/apache/pekko/http/impl/engine/parsing/HttpHeaderParser.scala
@@ -189,7 +189,7 @@ private[engine] final class HttpHeaderParser private (
         case (c, IllegalResponseHeaderNameProcessingMode.Error) =>
           fail(s"Illegal character '${escape(c)}' in header name")
         case (c, IllegalResponseHeaderNameProcessingMode.Warn) =>
-          log.warning(s"Header key contains illegal character '${escape(c)}'")
+          log.warning("Header key contains illegal character '{}'", escape(c))
           scanHeaderNameAndReturnIndexOfColon(input, start, limit)(ix + 1)
         case (c, IllegalResponseHeaderNameProcessingMode.Ignore) =>
           scanHeaderNameAndReturnIndexOfColon(input, start, limit)(ix + 1)
@@ -649,7 +649,7 @@ private[http] object HttpHeaderParser {
                   fail(s"Illegal character '${escape(c)}' in header value")
                 case IllegalResponseHeaderValueProcessingMode.Warn =>
                   // ignore the illegal character and log a warning message
-                  log.warning(s"Illegal character '${escape(c)}' in header 
value")
+                  log.warning("Illegal character '{}' in header value", 
escape(c))
                   sb
                 case IllegalResponseHeaderValueProcessingMode.Ignore =>
                   // just ignore the illegal character
diff --git 
a/http-core/src/main/scala/org/apache/pekko/http/impl/util/StreamUtils.scala 
b/http-core/src/main/scala/org/apache/pekko/http/impl/util/StreamUtils.scala
index aa6ce6a6c..2c0f426c2 100644
--- a/http-core/src/main/scala/org/apache/pekko/http/impl/util/StreamUtils.scala
+++ b/http-core/src/main/scala/org/apache/pekko/http/impl/util/StreamUtils.scala
@@ -228,10 +228,10 @@ private[http] object StreamUtils {
         override def onDownstreamFinish(cause: Throwable): Unit = {
           cancelAfter match {
             case finite: FiniteDuration =>
-              log.debug(s"Delaying cancellation for $finite")
+              log.debug("Delaying cancellation for {}", finite)
               timeout = OptionVal.Some {
                 scheduleOnce(finite) {
-                  log.debug(s"Stage was canceled after delay of $cancelAfter")
+                  log.debug("Stage was canceled after delay of {}", 
cancelAfter)
                   timeout = OptionVal.None
                   completeStage()
                 }
diff --git 
a/http-core/src/main/scala/org/apache/pekko/http/impl/util/package.scala 
b/http-core/src/main/scala/org/apache/pekko/http/impl/util/package.scala
index 191958b66..a1cf26380 100644
--- a/http-core/src/main/scala/org/apache/pekko/http/impl/util/package.scala
+++ b/http-core/src/main/scala/org/apache/pekko/http/impl/util/package.scala
@@ -176,7 +176,7 @@ package util {
       new Receive {
         def isDefinedAt(x: Any): Boolean = r.isDefinedAt(x)
         def apply(x: Any): Unit = {
-          log.debug(s"[$mark] received: $x")
+          log.debug("[{}] received: {}", mark, x)
           r(x)
         }
       }
diff --git 
a/http-core/src/test/scala/org/apache/pekko/http/impl/engine/client/HostConnectionPoolSpec.scala
 
b/http-core/src/test/scala/org/apache/pekko/http/impl/engine/client/HostConnectionPoolSpec.scala
index a0446db4e..d39a1080b 100644
--- 
a/http-core/src/test/scala/org/apache/pekko/http/impl/engine/client/HostConnectionPoolSpec.scala
+++ 
b/http-core/src/test/scala/org/apache/pekko/http/impl/engine/client/HostConnectionPoolSpec.scala
@@ -880,7 +880,7 @@ class HostConnectionPoolSpec extends 
PekkoSpecWithMaterializer(
             connectionProbe.ref ! serverConnection
           })
           .run().awaitResult(3.seconds)
-      system.log.debug(s"Server bound to [${serverBinding.localAddress}]")
+      system.log.debug("Server bound to [{}]", serverBinding.localAddress)
 
       // needs to be an involved two step process:
       //   1. setup client flow and proxies on the server side to be able to 
return that flow immediately
diff --git 
a/http-core/src/test/scala/org/apache/pekko/http/scaladsl/ClientServerSpec.scala
 
b/http-core/src/test/scala/org/apache/pekko/http/scaladsl/ClientServerSpec.scala
index 068b3a1e0..57d9b1151 100644
--- 
a/http-core/src/test/scala/org/apache/pekko/http/scaladsl/ClientServerSpec.scala
+++ 
b/http-core/src/test/scala/org/apache/pekko/http/scaladsl/ClientServerSpec.scala
@@ -643,7 +643,7 @@ abstract class ClientServerSpecBase(http2: Boolean) extends 
PekkoSpecWithMateria
         Http().singleRequest(request(i), settings = clientSettings).futureValue
           .entity.dataBytes.runFold(ByteString.empty) { (prev, cur) =>
             val res = prev ++ cur
-            system.log.debug(s"Received ${res.size} of 
[${res.take(1).utf8String}]")
+            system.log.debug("Received {} of [{}]", res.size, 
res.take(1).utf8String)
             res
           }.futureValue
           .size shouldBe responseSize
diff --git 
a/http-core/src/test/scala/org/apache/pekko/http/scaladsl/GracefulTerminationSpec.scala
 
b/http-core/src/test/scala/org/apache/pekko/http/scaladsl/GracefulTerminationSpec.scala
index e4b6481ef..0368c321a 100644
--- 
a/http-core/src/test/scala/org/apache/pekko/http/scaladsl/GracefulTerminationSpec.scala
+++ 
b/http-core/src/test/scala/org/apache/pekko/http/scaladsl/GracefulTerminationSpec.scala
@@ -232,7 +232,7 @@ class GracefulTerminationSpec
                   conn.onComplete {
                     case Success(s)  => result.trySuccess(s)
                     case Failure(ex) =>
-                      log.debug(s"Delaying failure ${ex.getMessage}")
+                      log.debug("Delaying failure {}", ex.getMessage)
                       
system.scheduler.scheduleOnce(100.millis)(result.tryFailure(ex))
                   }
                   result.future
diff --git 
a/http-tests/src/test/scala/org/apache/pekko/http/scaladsl/server/DontLeakActorsOnFailingConnectionSpecs.scala
 
b/http-tests/src/test/scala/org/apache/pekko/http/scaladsl/server/DontLeakActorsOnFailingConnectionSpecs.scala
index fdf71fe22..b2b44aca1 100644
--- 
a/http-tests/src/test/scala/org/apache/pekko/http/scaladsl/server/DontLeakActorsOnFailingConnectionSpecs.scala
+++ 
b/http-tests/src/test/scala/org/apache/pekko/http/scaladsl/server/DontLeakActorsOnFailingConnectionSpecs.scala
@@ -84,11 +84,11 @@ abstract class 
DontLeakActorsOnFailingConnectionSpecs(poolImplementation: String
   private def handleResponse(httpResp: Try[HttpResponse], id: Int): Unit = {
     httpResp match {
       case Success(httpRes) =>
-        system.log.error(s"$id: OK: (${httpRes.status.intValue}")
+        system.log.error("{}: OK: ({}", id, httpRes.status.intValue)
         httpRes.entity.dataBytes.runWith(Sink.ignore)
 
       case Failure(ex) =>
-        system.log.debug(s"$id: FAIL $ex") // this is what we expect
+        system.log.debug("{}: FAIL {}", id, ex) // this is what we expect
     }
   }
 
diff --git 
a/http/src/main/scala/org/apache/pekko/http/scaladsl/server/directives/FileAndResourceDirectives.scala
 
b/http/src/main/scala/org/apache/pekko/http/scaladsl/server/directives/FileAndResourceDirectives.scala
index eb05cc23f..c425568c8 100644
--- 
a/http/src/main/scala/org/apache/pekko/http/scaladsl/server/directives/FileAndResourceDirectives.scala
+++ 
b/http/src/main/scala/org/apache/pekko/http/scaladsl/server/directives/FileAndResourceDirectives.scala
@@ -271,8 +271,8 @@ object FileAndResourceDirectives extends 
FileAndResourceDirectives {
     val canonicalFinalPath = finalFile.getCanonicalPath
 
     if (!canonicalFinalPath.startsWith(baseFile.getCanonicalPath)) {
-      log.warning(s"[$finalFile] points to a location that is not part of 
[$baseFile]. This might be a directory " +
-        "traversal attempt.")
+      log.warning("[{}] points to a location that is not part of [{}]. This 
might be a directory traversal attempt.",
+        finalFile, baseFile)
       ""
     } else canonicalFinalPath
   }
diff --git 
a/http2-tests/src/test/scala/org/apache/pekko/http/impl/engine/http2/H2SpecIntegrationSpec.scala
 
b/http2-tests/src/test/scala/org/apache/pekko/http/impl/engine/http2/H2SpecIntegrationSpec.scala
index e80cd87f4..b6c1719e7 100644
--- 
a/http2-tests/src/test/scala/org/apache/pekko/http/impl/engine/http2/H2SpecIntegrationSpec.scala
+++ 
b/http2-tests/src/test/scala/org/apache/pekko/http/impl/engine/http2/H2SpecIntegrationSpec.scala
@@ -311,7 +311,7 @@ class H2SpecIntegrationSpec extends PekkoFreeSpec(
           "-j", junitOutput.getPath) ++
         specSectionNumber.toList.map(number => s"http2/$number")
 
-      log.debug(s"Executing h2spec: $command")
+      log.debug("Executing h2spec: {}", command)
       val aggregateTckLogs = ProcessLogger(
         out => {
           if (out.contains("All tests passed")) ()


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to