QuickKnol: Integrating Logback with Scala

Logback is the successor of Log4j and is one of the better logging frameworks around. In this post, we would quickly see how to set it up on a Scala project and how to start using it.

The relevant dependency to be included in your build.sbt is

libraryDependencies += “ch.qos.logback” % “logback-classic” % “1.0.1”

Once, you have this set, next you have to get a logback.xml file in your classpath. If you are using a sbt generated project, the best place to put it would be /src/main/resources and for your tests, you could put a logback-test.xml in /src/test/resources

A sample, logback.xml file would look like this

Once these are done, next let us just test it out. Following is a small Scala program to check

and the output

Entire code for this sample is present on the Knoldus github site

Happy Logging.

Written by 

Vikas is the CEO and Co-Founder of Knoldus Inc. Knoldus does niche Reactive and Big Data product development on Scala, Spark, and Functional Java. Knoldus has a strong focus on software craftsmanship which ensures high-quality software development. It partners with the best in the industry like Lightbend (Scala Ecosystem), Databricks (Spark Ecosystem), Confluent (Kafka) and Datastax (Cassandra). Vikas has been working in the cutting edge tech industry for 20+ years. He was an ardent fan of Java with multiple high load enterprise systems to boast of till he met Scala. His current passions include utilizing the power of Scala, Akka and Play to make Reactive and Big Data systems for niche startups and enterprises who would like to change the way software is developed. To know more, send a mail to hello@knoldus.com or visit www.knoldus.com

1 thought on “QuickKnol: Integrating Logback with Scala

  1. Hi, good post. But I think you still need as dependencies:

    “org.slf4j” % “slf4j-api” % “1.7.1”,
    “ch.qos.logback” % “logback-core” % “1.0.7”,
    “ch.qos.logback” % “logback-classic” % “1.0.7”,

Leave a Reply

%d bloggers like this: