diff --git a/actor-testkit-typed/src/main/scala/org/apache/pekko/actor/testkit/typed/internal/TestAppender.scala b/actor-testkit-typed/src/main/scala/org/apache/pekko/actor/testkit/typed/internal/TestAppender.scala index d2d86099443..ddfe5f34458 100644 --- a/actor-testkit-typed/src/main/scala/org/apache/pekko/actor/testkit/typed/internal/TestAppender.scala +++ b/actor-testkit-typed/src/main/scala/org/apache/pekko/actor/testkit/typed/internal/TestAppender.scala @@ -16,12 +16,13 @@ package org.apache.pekko.actor.testkit.typed.internal import ch.qos.logback.classic.spi.ILoggingEvent import ch.qos.logback.classic.spi.ThrowableProxy import ch.qos.logback.core.AppenderBase -import org.slf4j.Marker - +import org.slf4j.{ MDC, Marker } import org.apache.pekko import pekko.actor.testkit.typed.LoggingEvent import pekko.annotation.InternalApi +import java.util.Collections + /** * INTERNAL API * @@ -90,6 +91,12 @@ import pekko.annotation.InternalApi } val marker: Option[Marker] = Option(event.getMarkerList).flatMap(_.asScala.headOption) + val mdc: Map[String, String] = Option(event.getMDCPropertyMap) + .filterNot(_.isEmpty) + .orElse(Option(MDC.getMDCAdapter.getCopyOfContextMap)) + .getOrElse(Collections.emptyMap()) + .asScala.toMap + val loggingEvent = LoggingEvent( level = convertLevel(event.getLevel), message = event.getFormattedMessage, @@ -98,7 +105,7 @@ import pekko.annotation.InternalApi timeStamp = event.getTimeStamp, marker = marker, throwable = throwable, - mdc = event.getMDCPropertyMap.asScala.toMap) + mdc = mdc) filter(loggingEvent) } diff --git a/cluster-typed/src/test/scala/org/apache/pekko/cluster/typed/ClusterActorLoggingSpec.scala b/cluster-typed/src/test/scala/org/apache/pekko/cluster/typed/ClusterActorLoggingSpec.scala index b0dfe770dc9..f32d43e194c 100644 --- a/cluster-typed/src/test/scala/org/apache/pekko/cluster/typed/ClusterActorLoggingSpec.scala +++ b/cluster-typed/src/test/scala/org/apache/pekko/cluster/typed/ClusterActorLoggingSpec.scala @@ -28,12 +28,8 @@ import pekko.actor.typed.scaladsl.Behaviors object ClusterActorLoggingSpec { def config = ConfigFactory.parseString(""" pekko.actor.provider = cluster - pekko.remote.classic.netty.tcp.port = 0 pekko.remote.artery.canonical.port = 0 pekko.remote.artery.canonical.hostname = 127.0.0.1 - # generous timeout for cluster forming probes - pekko.actor.testkit.typed.default-timeout = 10s - pekko.actor.testkit.typed.filter-leeway = 10s """) } @@ -58,8 +54,10 @@ class ClusterActorLoggingSpec LoggingTestKit .info("Starting") .withCustom { event => + event.mdc.contains(ActorMdc.PekkoAddressKey) && event.mdc(ActorMdc.PekkoAddressKey) == addressString } + .withLoggerName("org.apache.pekko.cluster.typed.ClusterActorLoggingSpec") .expect { spawn(behavior) }