使用logback.groovy配置播放框架日志记录

时间:2016-07-22 16:56:43

标签: playframework playframework-2.5 logback-groovy

是否可以使用logback.groovy而不是logback.xml配置2.5 PlayFramework日志记录?

我的课程路径上有logback.groovy。我知道这是有效的,因为它最初加载时没有错误,甚至创建空的日志文件。

播放然后重新初始化记录器。如果我启动激活器并执行

[myProj] $ run -Dlogger.resource=/logback.groovy 9999

尝试加载网页时出错:

ch.qos.logback.core.joran.spi.JoranException: Problem parsing XML document. See previously reported errors.
     ch.qos.logback.core.joran.event.SaxEventRecorder.recordEvents(SaxEventRecorder.java:67)
     ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:134)
     ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:99)
     ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:49)
     play.api.libs.logback.LogbackLoggerConfigurator.configure(LogbackLoggerConfigurator.scala:91)
     play.api.libs.logback.LogbackLoggerConfigurator.configure(LogbackLoggerConfigurator.scala:59)
     play.api.inject.guice.GuiceApplicationBuilder$$anonfun$applicationModule$1.apply(GuiceApplicationBuilder.scala:102)
     play.api.inject.guice.GuiceApplicationBuilder$$anonfun$applicationModule$1.apply(GuiceApplicationBuilder.scala:102)
     scala.Option.foreach(Option.scala:257)
     play.api.inject.guice.GuiceApplicationBuilder.applicationModule(GuiceApplicationBuilder.scala:101)
     play.api.inject.guice.GuiceBuilder.injector(GuiceInjectorBuilder.scala:181)
     play.api.inject.guice.GuiceApplicationBuilder.build(GuiceApplicationBuilder.scala:123)
     play.api.inject.guice.GuiceApplicationLoader.load(GuiceApplicationLoader.scala:21)
     play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1$$anonfun$apply$1$$anonfun$1$$anonfun$2.apply(DevServerStart.scala:158)
     play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1$$anonfun$apply$1$$anonfun$1$$anonfun$2.apply(DevServerStart.scala:155)
     play.utils.Threads$.withContextClassLoader(Threads.scala:21)
     play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1$$anonfun$apply$1$$anonfun$1.apply(DevServerStart.scala:155)
     play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1$$anonfun$apply$1$$anonfun$1.apply(DevServerStart.scala:126)
     scala.Option.map(Option.scala:146)
     play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1$$anonfun$apply$1.apply(DevServerStart.scala:126)
     play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1$$anonfun$apply$1.apply(DevServerStart.scala:124)
     scala.util.Success.flatMap(Try.scala:231)
     play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1.apply(DevServerStart.scala:124)
     play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1.apply(DevServerStart.scala:116)
     scala.concurrent.impl.Future$PromiseCompletingRunnable.liftedTree1$1(Future.scala:24)
     scala.concurrent.impl.Future$PromiseCompletingRunnable.run(Future.scala:24)
     java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec(ForkJoinTask.java:1402)
     java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
     java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
     java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
     java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)

鉴于错误消息引用了解析XML的错误,似乎Play假设该文件是XML。有没有办法使用groovy文件配置Play中的日志记录?

我想我可以第三次重新初始化日志记录,但必须有更好的方法。

1 个答案:

答案 0 :(得分:0)

我在这里回答了你的问题:

https://github.com/playframework/playframework/issues/7767

我想在此处添加您可以使用LogbackLoggerConfigurator作为起点编写自己的内容,因为它已经处理了大部分集成问题。