Logback classic 1.2.3 version works but if I use logback 1.3.0 alpha which uses sl4f 1.8 I get error :

SLF4J: No SLF4J providers were found. error

This happens only if I assemble the scala file, create a jar and execute it. If I run it from intellij IDE it works fine.

My sbt is:

libraryDependencies += "ch.qos.logback" % "logback-classic" % "1.3.0-alpha4"

And my scala code is:

import org.slf4j.LoggerFactory

object Hello extends App{
  print("Hi!!!")
  val logback = LoggerFactory.getLogger("CloudSim+")
  logback.info("   ---    Wecome to cloudsim+ simulator    ---    ")
  logback.info("Press 1 to start Load balancing simulator")
  logback.info("Press 2 to start Network simulator")
}

logbacl.xml in resources folder has below content:

<configuration>

    <appender name="console" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>[%date{HH:mm:ss}] %-5level %logger{0} {%class %method} - %msg%n</pattern>
        </encoder>
    </appender>

    <appender name="file" class="ch.qos.logback.core.FileAppender">
        <file>${log-file:-scala-logging.log}</file>
        <encoder>
            <pattern>[%date{HH:mm:ss}] %-5level %logger{0} {%class %method} - %msg%n</pattern>
        </encoder>
    </appender>

    <root level="info">
        <appender-ref ref="console"/>
        <appender-ref ref="file"/>
    </root>

</configuration>

I'm stuck I tried various things to see log statements even when I run a jar file.

0 Answers