3

I wrote my own logback adapter class. When I start the program with the respective class file in the classpath directly (inside a directory), logback can't find it.

ERROR in ch.qos.logback.core.joran.action.AppenderAction - Could not create an Appender of type [com....MyAppender]. ch.qos.logback.core.util.DynamicClassLoadingException: Failed to instantiate type com....MyAppender
at ch.qos.logback.core.util.DynamicClassLoadingException: Failed to instantiate type com....MyAppender
at ch.qos.logback.core.util.OptionHelper.instantiateByClassNameAndParameter(OptionHelper.java:73)
at ch.qos.logback.core.util.OptionHelper.instantiateByClassName(OptionHelper.java:48)

If I put it in a jar file, everything is fine.

I saw that logback is using it's own class loader and my problem occurs when I start my application using sbt and play. So the problem may lay there.

Any ideas on how I could troubleshoot this?

Using:

"com.typesafe.play" %% "play" % "2.3.9"
"ch.qos.logback" % "logback-core" % "1.1.3",
sbt launcher version 0.13.8
max.ott
  • 569
  • 1
  • 6
  • 16

2 Answers2

1

I saw similar issue Play fails to load custom log back appender but it is still not resolved.

Proposed solution just leave it as is - it will work in the prod mode because all code would be precompiled in jar files. I hope you tried it in the prod mode as well.

Community
  • 1
  • 1
Andriy Kuba
  • 8,093
  • 2
  • 29
  • 46
  • 1
    Yes, everyone works fine in product mode. It's just a pain to debug issues as you end up with all kind of race conditions as the log adapters are being called very early in the life cycle of an application. But now I have to worry that my users aren't getting confused by error messages when they pick the wrong log config file during development. – max.ott Sep 17 '15 at 02:28
1

I believe Andriy's reference to the "Play fails to load custom log back appender" issue may contain the solution to the puzzle.

When logback tries to provision it's adapters, Play hasn't started up, yet. I suspect that the dynamic loading and recompiling mechanism of Play will also modify the class path. Meaning that the classpath at the time logback starts up doesn't yet include the target/scala-2.xx/classes path. This may be added later.

Community
  • 1
  • 1
max.ott
  • 569
  • 1
  • 6
  • 16