Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scalalogging will not work in sbt playproject with logging to stdout

My sbt is setup based on this great answer: Confused how to setup a multi project sbt project

So in the Dependencies.scala have added:

val scalaLogging = "com.typesafe.scala-logging" %% "scala-logging-slf4j" % scalaLoggingVersion
//val logbackCore = "ch.qos.logback" % "logback-core" % logbackVersion
val logbackClassic = "ch.qos.logback" % "logback-classic" % logbackVersion

(Have commented out logbackCore - Do I even need that?)

Have added scalaLogging and logbackClassic to commonDependencies (other libs removed):

val commonDependencies: Seq[ModuleID] = Seq(
    scalaLogging,
    //slf4j,
    //logbackCore,
    logbackClassic
)

Also in the /services sbt module , added this to a UserServiceImpl class:

import com.typesafe.scalalogging.slf4j.LazyLogging
class UserServiceImpl (.....) extends SecurityService with LazyLogging {

    def show(.....) {
        logger.trace("UserService.show called")
        logger.debug("UserService.show called")
    }
}

Also, in /services/resources , added logback.xml:

<configuration>

    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">

        <encoder>
            <pattern>%logger:%line - %msg%n</pattern>
        </encoder>
    </appender>

    <root level="debug">
        <appender-ref ref="STDOUT" />
    </root>

</configuration>

Now when my play app is launched , log is not seen when sbt run, regular play logs are just fine that I put in my controllers etc.

For good measure , have also dropped a logback.xml in the /conf folder, but still no output.

I'm not sure what I am doing wrong here, hoping someone can clarify things for me.

Note: I am using sbt to compile my project, but I make edits in IntelliJ and for some reason IntelliJ doesn't not pickup scala-logging correctly. My import is highlighted in red, my LazyLogging trait keyword that I am using on my UserService 'with LazyLogging' is in red. Also my actual log statements like logger.debug the word 'logger' is red. It doesnt' seem to resolve these, yet sbt compiles it fine.

like image 680
Blankman Avatar asked May 26 '14 03:05

Blankman


1 Answers

To make the logback working, you have to edit the application.conf and comment out all logger settings: logger.root, logger.play, logger.application, etc.

Then place a logback configuration in a file called application-logger.xml (the name is important) in your /conf directory.

like image 187
lpiepiora Avatar answered Nov 08 '22 18:11

lpiepiora