记录没有显示出来斯卡拉播放2.3.x版本(Logs not showing up Scala Pla

2019-10-21 20:16发布

我想我的日志我的戏控制台显示出来。 这里是一个控制器我试图从日志信息的例子:

import play.api.Logger
object LandingPage extends Controller {
  import ComponentRegistry._
  private val emailForm =
    Form(mapping("id" -> optional(of[Long]), "emailAddress" -> email)(Email.apply _)(Email.unapply _))
  def index = Action {
    Logger.info("Index method inside of LandingPage")
    Ok("INDEX")
  }

  def submit = Action { implicit request =>
    Logger.info("Inside of submit method in Landing Page controller")
    Ok("SUBMIT PAGE")

  }
}

以下是我在我的application.conf

#Logger provided to your application:
logger.application=INFO

我需要做什么修改,以获得输出中,从日志我的控制台显示?

编辑:这可能是有用的信息。 显然,我有多个SLF4J绑定

SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/home/chris/dev/suredbits-web/lib/suredbits-core-assembly-1.0.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/home/chris/.ivy2/cache/ch.qos.logback/logback-classic/jars/logback-classic-1.1.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.

不知道如何摆脱这些多重绑定。

也是我build.sbt

name := "suredbits-web" 

version := "0.0" 

lazy val root = (project in file(".")).enablePlugins(play.PlayScala, SbtWeb)

scalaVersion := "2.11.4" 

organization := "com.suredbits.web"

libraryDependencies ++= {  
    val sprayV = "1.3.2"
    val akkaV = "2.3.8" 
    val bootstrapV = "3.3.2"
    val webJarsPlayV = "2.3.0"
    Seq(
      "io.spray"            %%  "spray-can"     % sprayV withSources() withJavadoc(),
    "io.spray"            %%  "spray-routing" % sprayV withSources() withJavadoc(),
    "io.spray"            %%  "spray-testkit" % sprayV  % "test" withSources() withJavadoc(),
    "com.typesafe.akka"   %%  "akka-actor"    % akkaV withSources() withJavadoc(),
    "com.typesafe.akka"   %%  "akka-testkit"  % akkaV   % "test" withSources() withJavadoc(),
    "org.specs2"          %%  "specs2-core"   % "2.4.7-scalaz-7.0.6" % "test" withSources() withJavadoc(),
      "org.scalactic"               %%  "scalactic"     %   "2.2.1" % "test" withSources() withJavadoc(),
      "io.spray"            %%  "spray-json"    % "1.3.0" withSources() withJavadoc(),
      "com.github.nscala-time" %% "nscala-time" % "1.6.0" withSources() withJavadoc() ,
    "com.novocode"        % "junit-interface" % "0.10" % "test" withSources() withJavadoc(),
        "org.webjars"         %% "webjars-play"   % webJarsPlayV withSources() withJavadoc(),
        "org.webjars"         % "bootstrap"       % bootstrapV withSources() withJavadoc(), 
        "org.webjars"         % "font-awesome"    % "4.3.0-1", 
        "org.webjars"         % "jquery"          % "2.1.3", 
      "com.typesafe.slick"  %% "slick"          % "2.1.0" withSources() withJavadoc(),
    "com.typesafe.slick"  %% "slick-testkit"  % "2.1.0" % "test" withSources() withJavadoc(), 
      "org.postgresql"      % "postgresql"      % "9.3-1100-jdbc41" withSources() withJavadoc(), 
    "org.scalatestplus"   %% "play" % "1.2.0"   % "test" withSources() withJavadoc()
  )
}

testOptions += Tests.Argument(TestFrameworks.JUnit, "-q", "-v", "-s", "-a")

parallelExecution in Test := false

scalacOptions ++= Seq("-unchecked", "-deprecation", "-feature") 

includeFilter in (Assets, LessKeys.less) := "*.less"

Answer 1:

对于游戏应用程序的日志级别已经是INFO默认。

之所以没有日志输出可能与您的多个SLF4J绑定做。

游戏默认使用的logback。 显然,你已经包括(有何不同?)SLF4J在你的绑定suredbits-core-assembly项目。

游戏配置的logback记录,但可能不是你所使用的绑定记录。 即使你已包括的logback两次可能不会配置它SLF4J最终使用,因为不同的类加载器的记录。

你不应该定义任何SLF4J为核心项目的依赖绑定:

http://www.slf4j.org/manual.html#libraries

嵌入式组件,如库或框架不应申报任何SLF4J的依赖性结合,但仅依靠SLF4J的API。 当一个库宣布在特异性结合传递依赖,即绑定在终端用户否定SLF4J的目的罚款。 需要注意的是,宣布在结合非传递性依赖,例如,用于测试,不影响最终用户。

因此,除去依赖于SLF4J在你的核心项目结合或组装你的罐子时至少排除org.slf4j.impl包。



Answer 2:

我认为你必须设置为根记录的水平:

logger.root=INFO


文章来源: Logs not showing up Scala Play 2.3.x