1

I attempted to start sbt with sbt -Dpact.logLevel=DEBUG and it threw a class-cast exception.

[error] (pactVerify) java.lang.ClassCastException: class org.apache.logging.slf4j.Log4jLogger cannot be cast to class ch.qos.logback.classic.Logger (org.apache.logging.slf4j.Log4jLogger is in unnamed module of loader sbt.internal.MetaBuildLoader @2641e737; ch.qos.logback.classic.Logger is in unnamed module of loader sbt.internal.PluginManagement$PluginClassLoader @ee2ae9a)
[error]     at au.com.dius.pact.provider.sbt.SbtProviderPlugin$autoImport$.$anonfun$pactProvidersConfig$2(SbtProviderPlugin.scala:26)
[error]     at au.com.dius.pact.provider.sbt.SbtProviderPlugin$autoImport$.$anonfun$pactProvidersConfig$2$adapted(SbtProviderPlugin.scala:22)
[error]     at scala.Function1.$anonfun$compose$1(Function1.scala:49)
[error]     at sbt.internal.util.$tilde$greater.$anonfun$$u2219$1(TypeFunctions.scala:63)
[error]     at sbt.std.Transform$$anon$4.work(Transform.scala:69)
[error]     at sbt.Execute.$anonfun$submit$2(Execute.scala:283)
[error]     at sbt.internal.util.ErrorHandling$.wideConvert(ErrorHandling.scala:24)
[error]     at sbt.Execute.work(Execute.scala:292)
[error]     at sbt.Execute.$anonfun$submit$1(Execute.scala:283)
[error]     at sbt.ConcurrentRestrictions$$anon$4.$anonfun$submitValid$1(ConcurrentRestrictions.scala:265)
[error]     at sbt.CompletionService$$anon$2.call(CompletionService.scala:65)
[error]     at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
[error]     at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)
[error]     at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
[error]     at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
[error]     at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
[error]     at java.base/java.lang.Thread.run(Thread.java:840)

It looks like it is expecting the log4j logging system, but it is getting the logback system. (My build.sbt does include logback in the dependencies.). Is there a way to set the log level in this case?

project/plugins.sbt includes

libraryDependencySchemes += "org.scala-lang.modules" %% "scala-xml"  % VersionScheme.Always
addSbtPlugin("au.com.dius" %% "pact-jvm-provider-sbt" % "3.5.12")

The library schemes is needed to avoid conflicts in org.scala-lang.modules:scala-xml_2.12 which appeared when I added the pact plugin.

1 Answer 1

2

It looks like it is expecting the log4j logging system, but it is getting the logback system.

I believe it's the opposite; the Pact code in question will only work with a Logback backend:

        if (System.getProperty("pact.logLevel") != null) {
          LoggerFactory.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME).asInstanceOf[LogbackLogger].setLevel(
            Level.toLevel(System.getProperty("pact.logLevel"))
          )
        }

When Log4j is in use, the cast fails.

However, you may not need to use pact.logLevel here: it's just a Logback-specific shortcut for configuring the root level. You can configure Log4j directly (e.g. this question) with the appropriate root logger level.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.