replace akka based names in logging code (#197)

This commit is contained in:
PJ Fanning 2023-02-16 10:46:33 +01:00 committed by GitHub
parent 3ee028f915
commit 2824a44abe
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 112 additions and 112 deletions

View file

@ -67,13 +67,13 @@ class Slf4jLogger extends Actor with SLF4JLogging with RequiresMessageQueue[Logg
val mdcThreadAttributeName = "sourceThread"
val mdcActorSystemAttributeName = "sourceActorSystem"
val mdcAkkaSourceAttributeName = "akkaSource"
val mdcAkkaTimestamp = "akkaTimestamp"
val mdcAkkaAddressAttributeName = "akkaAddress"
val mdcAkkaUidAttributeName = "akkaUid"
val mdcPekkoSourceAttributeName = "pekkoSource"
val mdcPekkoTimestamp = "pekkoTimestamp"
val mdcPekkoAddressAttributeName = "pekkoAddress"
val mdcPekkoUidAttributeName = "pekkoUid"
private def akkaAddress = context.system.asInstanceOf[ExtendedActorSystem].provider.addressString
private val akkaUid: String = context.system.asInstanceOf[ExtendedActorSystem].uid.toString
private def pekkoAddress = context.system.asInstanceOf[ExtendedActorSystem].provider.addressString
private val pekkoUid: String = context.system.asInstanceOf[ExtendedActorSystem].uid.toString
def receive = {
@ -129,12 +129,12 @@ class Slf4jLogger extends Actor with SLF4JLogging with RequiresMessageQueue[Logg
case _ =>
}
MDC.put(mdcAkkaSourceAttributeName, logSource)
MDC.put(mdcPekkoSourceAttributeName, logSource)
MDC.put(mdcThreadAttributeName, logEvent.thread.getName)
MDC.put(mdcAkkaTimestamp, formatTimestamp(logEvent.timestamp))
MDC.put(mdcPekkoTimestamp, formatTimestamp(logEvent.timestamp))
MDC.put(mdcActorSystemAttributeName, context.system.name)
MDC.put(mdcAkkaAddressAttributeName, akkaAddress)
MDC.put(mdcAkkaUidAttributeName, akkaUid)
MDC.put(mdcPekkoAddressAttributeName, pekkoAddress)
MDC.put(mdcPekkoUidAttributeName, pekkoUid)
logEvent.mdc.foreach { case (k, v) => MDC.put(k, String.valueOf(v)) }
try logStatement

View file

@ -2,7 +2,7 @@
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%date{ISO8601} %-5level %logger %X{akkaSource} %X{sourceThread} - %msg%n</pattern>
<pattern>%date{ISO8601} %-5level %logger %X{pekkoSource} %X{sourceThread} - %msg%n</pattern>
</encoder>
</appender>
<appender name="TEST" class="org.apache.pekko.event.slf4j.Slf4jLoggerSpec$TestAppender">

View file

@ -101,9 +101,9 @@ class Slf4jLoggerSpec extends PekkoSpec(Slf4jLoggerSpec.config) with BeforeAndAf
awaitCond(outputString.contains("----"), 5 seconds)
val s = outputString
s should include("akkaSource=akka://Slf4jLoggerSpec/user/logProducer")
s should include("akkaAddress=akka://Slf4jLoggerSpec")
s should include("akkaUid=")
s should include("pekkoSource=akka://Slf4jLoggerSpec/user/logProducer")
s should include("pekkoAddress=akka://Slf4jLoggerSpec")
s should include("pekkoUid=")
s should include("level=[ERROR]")
s should include("logger=[org.apache.pekko.event.slf4j.Slf4jLoggerSpec$LogProducer]")
(s should include).regex(sourceThreadRegex)
@ -117,8 +117,8 @@ class Slf4jLoggerSpec extends PekkoSpec(Slf4jLoggerSpec.config) with BeforeAndAf
awaitCond(outputString.contains("----"), 5 seconds)
val s = outputString
s should include("akkaSource=akka://Slf4jLoggerSpec/user/logProducer")
s should include("akkaAddress=akka://Slf4jLoggerSpec")
s should include("pekkoSource=akka://Slf4jLoggerSpec/user/logProducer")
s should include("pekkoAddress=akka://Slf4jLoggerSpec")
s should include("level=[INFO]")
s should include("logger=[org.apache.pekko.event.slf4j.Slf4jLoggerSpec$LogProducer]")
(s should include).regex(sourceThreadRegex)
@ -177,7 +177,7 @@ class Slf4jLoggerSpec extends PekkoSpec(Slf4jLoggerSpec.config) with BeforeAndAf
awaitCond(outputString.contains("----"), 5 seconds)
val s = outputString
s should include("akkaSource=akka://Slf4jLoggerSpec/user/logProducer")
s should include("pekkoSource=akka://Slf4jLoggerSpec/user/logProducer")
s should include("level=[INFO]")
s should include("logger=[org.apache.pekko.event.slf4j.Slf4jLoggerSpec$LogProducer]")
(s should include).regex(sourceThreadRegex)
@ -198,7 +198,7 @@ class Slf4jLoggerSpec extends PekkoSpec(Slf4jLoggerSpec.config) with BeforeAndAf
awaitCond(outputString.contains("----"), 5 seconds)
val s = outputString
s should include("akkaSource=akka://Slf4jLoggerSpec/user/logProducer")
s should include("pekkoSource=akka://Slf4jLoggerSpec/user/logProducer")
s should include("level=[INFO]")
s should include("logger=[org.apache.pekko.event.slf4j.Slf4jLoggerSpec$LogProducer]")
println(s)
@ -207,39 +207,39 @@ class Slf4jLoggerSpec extends PekkoSpec(Slf4jLoggerSpec.config) with BeforeAndAf
s should include("msg=[Message with null custom MDC values]")
}
"include system info in akkaSource when creating Logging with system" in {
"include system info in pekkoSource when creating Logging with system" in {
val log = Logging(system, "org.apache.pekko.event.slf4j.Slf4jLoggerSpec.MyLogSource")
log.info("test")
awaitCond(outputString.contains("----"), 5 seconds)
val s = outputString
s should include("akkaSource=org.apache.pekko.event.slf4j.Slf4jLoggerSpec.MyLogSource(akka://Slf4jLoggerSpec)")
s should include("pekkoSource=org.apache.pekko.event.slf4j.Slf4jLoggerSpec.MyLogSource(akka://Slf4jLoggerSpec)")
s should include("logger=[org.apache.pekko.event.slf4j.Slf4jLoggerSpec.MyLogSource(akka://Slf4jLoggerSpec)]")
}
"not include system info in akkaSource when creating Logging with system.eventStream" in {
"not include system info in pekkoSource when creating Logging with system.eventStream" in {
val log = Logging(system.eventStream, "org.apache.pekko.event.slf4j.Slf4jLoggerSpec.MyLogSource")
log.info("test")
awaitCond(outputString.contains("----"), 5 seconds)
val s = outputString
s should include("akkaSource=org.apache.pekko.event.slf4j.Slf4jLoggerSpec.MyLogSource")
s should include("pekkoSource=org.apache.pekko.event.slf4j.Slf4jLoggerSpec.MyLogSource")
s should include("logger=[org.apache.pekko.event.slf4j.Slf4jLoggerSpec.MyLogSource]")
}
"use short class name and include system info in akkaSource when creating Logging with system and class" in {
"use short class name and include system info in pekkoSource when creating Logging with system and class" in {
val log = Logging(system, classOf[MyLogSource])
log.info("test")
awaitCond(outputString.contains("----"), 5 seconds)
val s = outputString
s should include("akkaSource=Slf4jLoggerSpec$MyLogSource(akka://Slf4jLoggerSpec)")
s should include("pekkoSource=Slf4jLoggerSpec$MyLogSource(akka://Slf4jLoggerSpec)")
s should include("logger=[org.apache.pekko.event.slf4j.Slf4jLoggerSpec$MyLogSource]")
}
"use short class name in akkaSource when creating Logging with system.eventStream and class" in {
"use short class name in pekkoSource when creating Logging with system.eventStream and class" in {
val log = Logging(system.eventStream, classOf[MyLogSource])
log.info("test")
awaitCond(outputString.contains("----"), 5 seconds)
val s = outputString
s should include("akkaSource=Slf4jLoggerSpec$MyLogSource")
s should include("pekkoSource=Slf4jLoggerSpec$MyLogSource")
s should include("logger=[org.apache.pekko.event.slf4j.Slf4jLoggerSpec$MyLogSource]")
}