Using scala-logger

Today I was adding logging to one of my projects. I decided to use scala-logger. I added scala-logger dependency to the build.sbt, excuted my test class and got the following error in the Eclipse console output:

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See for further details.

I initially thought it had to do with logback.xml missing from my project, so I added it to the resource directory. Executed my test class again and got the same result. After some Googling it turns out you have to add logback-classic to the sbt dependencies.

These are the required dependencies:

libraryDependencies += "com.typesafe.scala-logging" %% "scala-logging" % "3.1.0"
libraryDependencies += "ch.qos.logback" % "logback-classic" % "1.1.2"

Just to be complete here is the logback.xml I am using:

  <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
    <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
  <appender name="FILE" class="ch.qos.logback.core.FileAppender">
      <pattern>%date %-5level [%thread] - [%logger] - %msg%n</pattern>
  <root level="DEBUG">
    <appender-ref ref="STDOUT" />
    <appender-ref ref="FILE" />

Happy coding!


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s