Reputation: 96
Here is the build.sbt file where i added the logback dependency
ThisBuild / version := "0.1.0-SNAPSHOT"
ThisBuild / scalaVersion := "2.13.8"
libraryDependencies ++= Seq(
"com.typesafe.akka" %% "akka-actor" % "2.6.3",
"ch.qos.logback" % "logback-classic" % "1.4.4" % Test
)
lazy val root = (project in file("."))
.settings(
name := "logBack"
)
Here is the logback.xml file, logBack is my project name
<configuration>
<appender name="logBack" class="ch.qos.logback.core.FileAppender">
<File>/tmp/logBack.log</File>
<encoder>
<pattern>%d{HH:mm:ss.SSS} %r [%thread] %logger{0} %level - %msg%n</pattern>
</encoder>
</appender>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} %r [%thread] %logger{0} %level - %msg%n</pattern>
</encoder>
</appender>
<logger name="interpretlogger" level="debug" additivity="false">
<appender-ref ref="STDOUT"/>
<appender-ref ref="Interpret"/>
</logger>
<root level="debug">
<appender-ref ref="logBack"/>
<appender-ref ref="STDOUT"/>
</root>
</configuration>
here is my scala file (logPractice)
import com.sun.org.slf4j.internal.LoggerFactory
object logPractice extends App{
val logger = LoggerFactory.getLogger(this.getClass)
logger.debug("Asif")
logger.error("Invalid Query")
}
Error
Exception in thread "main" java.lang.IllegalAccessError: class logPractice$ (in unnamed module @0x31dc339b) cannot access class com.sun.org.slf4j.internal.LoggerFactory (in module java.xml.crypto) because module java.xml.crypto does not export com.sun.org.slf4j.internal to unnamed module @0x31dc339b
at logPractice$.delayedEndpoint$logPractice$1(logPractice.scala:5)
at logPractice$delayedInit$body.apply(logPractice.scala:3)
at scala.Function0.apply$mcV$sp(Function0.scala:39)
at scala.Function0.apply$mcV$sp$(Function0.scala:39)
at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:17)
at scala.App.$anonfun$main$1(App.scala:76)
at scala.App.$anonfun$main$1$adapted(App.scala:76)
at scala.collection.IterableOnceOps.foreach(IterableOnce.scala:563)
at scala.collection.IterableOnceOps.foreach$(IterableOnce.scala:561)
at scala.collection.AbstractIterable.foreach(Iterable.scala:926)
at scala.App.main(App.scala:76)
at scala.App.main$(App.scala:74)
at logPractice$.main(logPractice.scala:3)
at logPractice.main(logPractice.scala)
Moreover the object of logger don not run the logger.info() and generate and error
Upvotes: 0
Views: 436
Reputation: 96
it has been resolved by importing the library
import org.slf4j.LoggerFactory
Upvotes: 1