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 http://www.slf4j.org/codes.html#StaticLoggerBinder 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:

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

Happy coding!

Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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