无法加载配置中的Scala记录器

时间:2017-11-11 12:47:06

标签: scala logging intellij-idea

我正在学习Scala + Akka,我想在我的网站上添加文件记录功能 小班,我正在使用Intellij Idea 这就是我所做的:

  • 添加了对build.sbt的依赖
  • 在src / main / resources目录中创建了application.conf文件
  • 创建了logback.xml文件

application.conf文件:

  akka {
  loggers = ["akka.event.slf4j.Slf4jLogger"]
  loglevel = "INFO"}

build.sbt文件:

  libraryDependencies ++= Seq(
  "com.typesafe.akka" %% "akka-actor" % "2.5.6",
  "com.typesafe.akka" %% "akka-testkit" % "2.5.6" % Test,
  "com.typesafe.akka" %% "akka-http" % "10.0.10",
  "com.typesafe.akka" %% "akka-http-testkit" % "10.0.10" % Test,
  "ch.qos.logback" % "logback-classic" % "1.2.3")

logback.xml文件:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>

    <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
        <target>System.out</target>
        <encoder>
            <pattern>%X{akkaTimestamp} %-5level[%thread] %logger{0} - %msg%n</pattern>
        </encoder>
    </appender>

    <appender name="FILE" class="ch.qos.logback.core.FileAppender">
        <file>C:/DEV/Projects/Scala/app.log</file>
        <append>true</append>
        <encoder>
            <pattern>%date{yyyy-MM-dd} %X{akkaTimestamp} %-5level[%thread] %logger{1} - %msg%n</pattern>
        </encoder>
    </appender>

    <logger name="akka" level="DEBUG" />

    <root level="DEBUG">
        <appender-ref ref="CONSOLE"/>
        <appender-ref ref="FILE"/>
    </root>

</configuration>

问题是,一旦我尝试运行项目,我就会遇到异常:

   error while starting up loggers
akka.ConfigurationException: Logger specified in config can't be loaded [akka.event.slf4j.Slf4jLogger] due to [java.lang.ClassNotFoundException: akka.event.slf4j.Slf4jLogger]
    at akka.event.LoggingBus$$anonfun$$nestedInanonfun$startDefaultLoggers$3$1.applyOrElse(Logging.scala:121)
    at akka.event.LoggingBus$$anonfun$$nestedInanonfun$startDefaultLoggers$3$1.applyOrElse(Logging.scala:118)
    at scala.runtime.AbstractPartialFunction.apply(AbstractPartialFunction.scala:34)
    at scala.util.Failure.recover(Try.scala:230)
    at akka.event.LoggingBus.$anonfun$startDefaultLoggers$3(Logging.scala:118)
    at scala.collection.TraversableLike$WithFilter.$anonfun$map$2(TraversableLike.scala:739)
    at scala.collection.Iterator.foreach(Iterator.scala:929)
    at scala.collection.Iterator.foreach$(Iterator.scala:929)
    at scala.collection.AbstractIterator.foreach(Iterator.scala:1417)
    at scala.collection.IterableLike.foreach(IterableLike.scala:71)
    at scala.collection.IterableLike.foreach$(IterableLike.scala:70)
    at scala.collection.AbstractIterable.foreach(Iterable.scala:54)
    at scala.collection.TraversableLike$WithFilter.map(TraversableLike.scala:738)
    at akka.event.LoggingBus.startDefaultLoggers(Logging.scala:113)
    at akka.event.LoggingBus.startDefaultLoggers$(Logging.scala:99)
    at akka.event.EventStream.startDefaultLoggers(EventStream.scala:28)
    at akka.actor.LocalActorRefProvider.init(ActorRefProvider.scala:667)
    at akka.actor.ActorSystemImpl.liftedTree2$1(ActorSystem.scala:828)
    at akka.actor.ActorSystemImpl._start$lzycompute(ActorSystem.scala:825)
    at akka.actor.ActorSystemImpl._start(ActorSystem.scala:825)
    at akka.actor.ActorSystemImpl.start(ActorSystem.scala:841)
    at akka.actor.ActorSystem$.apply(ActorSystem.scala:245)
    at akka.actor.ActorSystem$.apply(ActorSystem.scala:288)
    at akka.actor.ActorSystem$.apply(ActorSystem.scala:233)
    at DateTimeService.<init>(DateTimeService.scala:16)
    at Reactor$.main(main.scala:6)
    at Reactor.main(main.scala)
Caused by: java.lang.ClassNotFoundException: akka.event.slf4j.Slf4jLogger
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:348)
    at akka.actor.ReflectiveDynamicAccess.$anonfun$getClassFor$1(ReflectiveDynamicAccess.scala:21)
    at scala.util.Try$.apply(Try.scala:209)
    at akka.actor.ReflectiveDynamicAccess.getClassFor(ReflectiveDynamicAccess.scala:20)
    at akka.event.LoggingBus.$anonfun$startDefaultLoggers$3(Logging.scala:116)
    ... 22 more
Exception in thread "main" akka.ConfigurationException: Could not start logger due to [akka.ConfigurationException: Logger specified in config can't be loaded [akka.event.slf4j.Slf4jLogger] due to [java.lang.ClassNotFoundException: akka.event.slf4j.Slf4jLogger]]
    at akka.event.LoggingBus.startDefaultLoggers(Logging.scala:147)
    at akka.event.LoggingBus.startDefaultLoggers$(Logging.scala:99)
    at akka.event.EventStream.startDefaultLoggers(EventStream.scala:28)
    at akka.actor.LocalActorRefProvider.init(ActorRefProvider.scala:667)
    at akka.actor.ActorSystemImpl.liftedTree2$1(ActorSystem.scala:828)
    at akka.actor.ActorSystemImpl._start$lzycompute(ActorSystem.scala:825)
    at akka.actor.ActorSystemImpl._start(ActorSystem.scala:825)
    at akka.actor.ActorSystemImpl.start(ActorSystem.scala:841)
    at akka.actor.ActorSystem$.apply(ActorSystem.scala:245)
    at akka.actor.ActorSystem$.apply(ActorSystem.scala:288)
    at akka.actor.ActorSystem$.apply(ActorSystem.scala:233)
    at DateTimeService.<init>(DateTimeService.scala:16)
    at Reactor$.main(main.scala:6)
    at Reactor.main(main.scala)

请问有人可以投光吗?

欢呼声

2 个答案:

答案 0 :(得分:1)

您缺少akka-slf4j依赖项:

  

&#34; com.typesafe.akka&#34; %%&#34; akka-slf4j&#34; %&#34; 2.5.6&#34;

答案 1 :(得分:0)

我想我知道为什么最后,在我点击&#34; Build Module ...&#34;之后,Intellij正在贬低依赖性问题。右下角的一个小窗口开始向我发送有关二进制兼容性的消息,暂时我将所有内容从2.5.6更改为2.4.19