Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
}
9 changes: 6 additions & 3 deletions actor/src/main/scala/org/apache/pekko/event/Logging.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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: _*)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if it's safe to change ,let's defer this.

case a: Array[?] => format(t, a.toIndexedSeq.asInstanceOf[IndexedSeq[AnyRef]]: _*)
case x => format(t, x)
}
}
Expand Down