This is an automated email from the ASF dual-hosted git repository.
He-Pin pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/pekko.git
The following commit(s) were added to refs/heads/main by this push:
new c0e9406bfd fix: expand Array arguments in MarkerLoggingAdapter log
templates (#3263)
c0e9406bfd is described below
commit c0e9406bfdf9794b78eff5266f7b9434e519af04
Author: He-Pin(kerr) <[email protected]>
AuthorDate: Mon Jun 29 03:39:26 2026 +0800
fix: expand Array arguments in MarkerLoggingAdapter log templates (#3263)
Motivation:
MarkerLoggingAdapter.format1 passed an Array argument to the varargs format
without spreading it, so the whole array was treated as a single template
argument. A call like markerLog.info(marker, "{} {} {}", Array("a", "b",
"c"))
rendered as "ArraySeq(a, b, c) {} {}" instead of "a b c". The base
LoggingAdapter expands arrays correctly; the marker copy did not.
DiagnosticMarkerBusLoggingAdapter inherits the same method and was affected
too.
Modification:
- Spread the array elements as varargs in both Array branches of
MarkerLoggingAdapter.format1 so each element fills its own placeholder.
Result:
Array arguments to the single-argument marker log template methods are now
expanded into separate placeholders, matching LoggingAdapter behavior.
Tests:
- actor-tests/testOnly org.apache.pekko.event.MarkerLoggingSpec - all
passed.
Added directional tests (non-primitive and primitive arrays) that fail
before the fix (rendering ArraySeq(...)) and pass after.
References:
Fixes #3257
---
.../org/apache/pekko/event/MarkerLoggingSpec.scala | 18 ++++++++++++++++++
.../main/scala/org/apache/pekko/event/Logging.scala | 9 ++++++---
2 files changed, 24 insertions(+), 3 deletions(-)
diff --git
a/actor-tests/src/test/scala/org/apache/pekko/event/MarkerLoggingSpec.scala
b/actor-tests/src/test/scala/org/apache/pekko/event/MarkerLoggingSpec.scala
index 2f967c4412..4a61fc7020 100644
--- a/actor-tests/src/test/scala/org/apache/pekko/event/MarkerLoggingSpec.scala
+++ b/actor-tests/src/test/scala/org/apache/pekko/event/MarkerLoggingSpec.scala
@@ -44,5 +44,23 @@ class MarkerLoggingSpec extends PekkoSpec with
ImplicitSender {
expectMsgType[Error].cause.getMessage should be("Security Exception")
}
+
+ "expand a non-primitive Array argument into separate template placeholders
(#3257)" in {
+ system.eventStream.subscribe(self, classOf[Info])
+ system.eventStream.publish(TestEvent.Mute(EventFilter.info()))
+
+ markerLogging.info(LogMarker.Security, "{} {} {}", Array("a", "b", "c"))
+
+ expectMsgType[Info3].message should be("a b c")
+ }
+
+ "expand a primitive Array argument into separate template placeholders
(#3257)" in {
+ system.eventStream.subscribe(self, classOf[Info])
+ system.eventStream.publish(TestEvent.Mute(EventFilter.info()))
+
+ markerLogging.info(LogMarker.Security, "{} {} {}", Array(1, 2, 3))
+
+ expectMsgType[Info3].message should be("1 2 3")
+ }
}
}
diff --git a/actor/src/main/scala/org/apache/pekko/event/Logging.scala
b/actor/src/main/scala/org/apache/pekko/event/Logging.scala
index 2cfefc1f27..3877e89f1e 100644
--- a/actor/src/main/scala/org/apache/pekko/event/Logging.scala
+++ b/actor/src/main/scala/org/apache/pekko/event/Logging.scala
@@ -2000,10 +2000,13 @@ class MarkerLoggingAdapter(
}
}
- // Copy of LoggingAdapter.format1 due to binary compatibility restrictions
+ // Copy of LoggingAdapter.format1 due to binary compatibility restrictions.
+ // The array branches must spread the elements as varargs (`: _*`) so that
each element is
+ // expanded into its own template placeholder; without it the whole
IndexedSeq would be passed
+ // as a single argument and rendered as e.g. "ArraySeq(a, b, c)" (issue
#3257).
private def format1(t: String, arg: Any): String = arg match {
- case a: Array[?] if !a.getClass.getComponentType.isPrimitive => format(t,
a.toIndexedSeq)
- case a: Array[?] => format(t,
a.toIndexedSeq.asInstanceOf[IndexedSeq[AnyRef]])
+ case a: Array[?] if !a.getClass.getComponentType.isPrimitive => format(t,
a.toIndexedSeq: _*)
+ case a: Array[?] => format(t,
a.toIndexedSeq.asInstanceOf[IndexedSeq[AnyRef]]: _*)
case x => format(t,
x)
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]