日志未显示Scala Play 2.3.x [英] Logs not showing up Scala Play 2.3.x

查看:73
本文介绍了日志未显示Scala Play 2.3.x的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将日志显示在我的游戏控制台中.这是我尝试从以下位置记录信息的控制器的示例:

I am trying to my logs to show up in my play console. Here is an example of a controller I am trying to log information from :

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

我需要修改什么才能使输出从日志显示在控制台中?

What do I need to modify to get ouput to show in my console from logs?

这可能是有用的信息.显然我有多个slf4j绑定

This might be useful info. Apparently I have multiple slf4j bindings

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.

不确定如何摆脱这些多重绑定.

Not sure how to get rid of these multiple bindings.

也是我的build.sbt

also my 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"

推荐答案

默认情况下,Play应用程序的日志级别为INFO.

The log level for a Play application already is INFO by default.

没有日志输出的原因可能与您的多个SLF4J绑定有关.

The reason for no logging output probably has to do with your multiple SLF4J bindings.

默认情况下,Play使用登录.显然,您在suredbits-core-assembly项目中包含了(不同的?)SLF4J绑定.

Play uses logback by default. Apparently you have included a (different?) SLF4J binding in your suredbits-core-assembly project.

Play会配置回滚记录器,但可能不会配置您正在使用的绑定的记录器.而且,即使您两次包含了logback,由于类加载器不同,它也可能无法配置SLF4J最终使用的记录器.

Play configures the logback logger, but probably not the logger of the binding you're using. And even if you have included logback twice it might not configure the logger which SLF4J eventually uses because of different class loaders.

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

You should not define any SLF4J binding as a dependency of your core project:

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

诸如库或框架之类的嵌入式组件不应声明对任何SLF4J绑定的依赖,而应仅依赖slf4j-api.当库声明对特定绑定的可传递依赖项时,该绑定将强加于最终用户,而否定了SLF4J的目的.请注意,声明对绑定的非传递性依赖关系(例如,用于测试)不会影响最终用户.

Embedded components such as libraries or frameworks should not declare a dependency on any SLF4J binding but only depend on slf4j-api. When a library declares a transitive dependency on a specific binding, that binding is imposed on the end-user negating the purpose of SLF4J. Note that declaring a non-transitive dependency on a binding, for example for testing, does not affect the end-user.

因此,在组装jar时,请删除对核心项目中SLF4J绑定的依赖,或者至少排除org.slf4j.impl包.

So, remove the dependency to the SLF4J binding in your core project or at least exclude the org.slf4j.impl package when assembling your jar.

这篇关于日志未显示Scala Play 2.3.x的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆