Merge pull request #29070 from ennru/log-capture-init
Typed testkit: log capture logger initalisation
This commit is contained in:
commit
5dc56a6d8c
1 changed files with 12 additions and 3 deletions
|
|
@ -6,9 +6,10 @@ package akka.actor.testkit.typed.internal
|
||||||
|
|
||||||
import org.slf4j.LoggerFactory
|
import org.slf4j.LoggerFactory
|
||||||
import org.slf4j.event.Level
|
import org.slf4j.event.Level
|
||||||
|
|
||||||
import akka.annotation.InternalApi
|
import akka.annotation.InternalApi
|
||||||
|
|
||||||
|
import scala.annotation.tailrec
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* INTERNAL API
|
* INTERNAL API
|
||||||
*/
|
*/
|
||||||
|
|
@ -16,9 +17,17 @@ import akka.annotation.InternalApi
|
||||||
def loggerNameOrRoot(loggerName: String): String =
|
def loggerNameOrRoot(loggerName: String): String =
|
||||||
if (loggerName == "") org.slf4j.Logger.ROOT_LOGGER_NAME else loggerName
|
if (loggerName == "") org.slf4j.Logger.ROOT_LOGGER_NAME else loggerName
|
||||||
|
|
||||||
def getLogbackLogger(loggerName: String): ch.qos.logback.classic.Logger = {
|
def getLogbackLogger(loggerName: String): ch.qos.logback.classic.Logger =
|
||||||
|
getLogbackLoggerInternal(loggerName, 50)
|
||||||
|
|
||||||
|
@tailrec
|
||||||
|
private def getLogbackLoggerInternal(loggerName: String, count: Int): ch.qos.logback.classic.Logger = {
|
||||||
LoggerFactory.getLogger(loggerNameOrRoot(loggerName)) match {
|
LoggerFactory.getLogger(loggerNameOrRoot(loggerName)) match {
|
||||||
case logger: ch.qos.logback.classic.Logger => logger
|
case logger: ch.qos.logback.classic.Logger => logger
|
||||||
|
case _: org.slf4j.helpers.SubstituteLogger if count > 0 =>
|
||||||
|
// Wait for logging initialisation http://www.slf4j.org/codes.html#substituteLogger
|
||||||
|
Thread.sleep(50)
|
||||||
|
getLogbackLoggerInternal(loggerName, count - 1)
|
||||||
case null =>
|
case null =>
|
||||||
throw new IllegalArgumentException(s"Couldn't find logger for [$loggerName].")
|
throw new IllegalArgumentException(s"Couldn't find logger for [$loggerName].")
|
||||||
case other =>
|
case other =>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue