Logs not showing up Scala Play 2.3.x

核能气质少年 提交于 2019-12-24 18:05:57

问题


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")

  }
}

Here is what I have in my 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?

EDIT: 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.

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"

回答1:


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

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

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

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.

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

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

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.

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.




回答2:


I think you have to set the level for the root logger:

logger.root=INFO


来源:https://stackoverflow.com/questions/28437431/logs-not-showing-up-scala-play-2-3-x

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!