【发布时间】:2013-12-09 22:18:42
【问题描述】:
新 Play2 应用程序中的 Global.scala:
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 中的记录器级别被重置为 ERROR。在scheduleOnce 之外,它们处于调试状态,而在内部,它们处于错误状态。如果我用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 我的确切 Play 版本是 2.1.4
标签: scala logging playframework-2.0 akka logback