Global.scala在新Play2應用:Akka計劃程序重置記錄器級別。爲什麼?
import play.api.{GlobalSettings, Application}
import play.api.libs.concurrent.Akka
import play.api.libs.concurrent.Execution.Implicits._
import play.api.Play
import play.api.Play.current
import scala.concurrent._
import scala.concurrent.duration._
import play.api.Logger
object Global extends GlobalSettings {
val logger = Logger("foo")
// `printLoggerLevels` prints logger levels
def printLoggerLevels(prepend:String) =
logger.error(
prepend +": "+
logger.isErrorEnabled +" "+
logger.isWarnEnabled +" "+
logger.isInfoEnabled +" "+
logger.isDebugEnabled +" "+
logger.isTraceEnabled
)
override def onStart(app: Application) {
printLoggerLevels("outside scheduleOnce")
Akka.system.scheduler.scheduleOnce(500 milliseconds) {
printLoggerLevels("inside scheduleOnce")
}
}
}
這將打印記錄器級別內外一個Akka.system.scheduler.scheduleOnce(500 milliseconds) {...}
像這樣:
$ play start 9000
[error] foo - outside scheduleOnce: true true true true false <----- notice this
[info] play - Starting application default Akka system.
[info] a.e.s.Slf4jEventHandler - Slf4jEventHandler started
[info] play - Application started (Prod)
[info] play - Listening for HTTP on /0:0:0:0:0:0:0:0:9000
[error] foo - inside scheduleOnce: true false false false false <----- and this
上面可以看到,裏面scheduleOnce
是記錄器級別被重置爲錯誤。在scheduleOnce
之外,它們在DEBUG上並且在ERROR中。如果我用play run
運行它,它會運行良好,並且水平將是相同的,但是當以play start
開始時,它們將被重置。
Application.conf:
logger.root=DEBUG
logger.play=INFO
logger.application=INFO
這是一個新的項目,我還沒有做出我沒有張貼任何變化。
爲什麼會發生這種情況?
編輯:另一種問這個問題的方法是:如何運行一個應用程序start
影響它的內部工作,反過來又如何影響傳遞給Akka調度程序的匿名函數中的日誌記錄級別?
編輯:玩的版本是2.1.4
你可以更具體的版本?這是Play 2.0.0嗎?在項目建設等方面,v2發佈之間有一些非常大的變化... – torbinsky
@torbinsky我的確切播放版本是2.1.4 –