Hi,

I've been trying to get JBehave (3.9.4) to work in one of my projects, but
I'm experiencing some odd behaviour with the slf4j binding. Hope somebody
can help to pinpoint it, and confirm, or deny, that JBehave, or its maven
plugin is a culprit here.

I'm using dropwizard (0.7.1) in my project which in turn uses logback, and
comes with all the logback dependencies as well as slf4j-api etc. Based on
that, Dropwizard seems to assume that
org.slf4j.LoggerFactory.getLogger(...) would always return an
implementation of ch.qos.logback.classic.Logger (they cast the result to
that Logger type).

I have a very simple JBehave test, which tries to start up the service
(dropwizard). When I run it from eclipse, everything works fine. However
when I run it from maven, when dropwizard's service is starting up, I'm
getting an exception like this:

Caused by: java.lang.ClassCastException: org.slf4j.impl.SimpleLogger cannot
be cast to ch.qos.logback.classic.Logger
at io.dropwizard.logging.LoggingFactory.bootstrap(LoggingFactory.java:37)
at io.dropwizard.logging.LoggingFactory.bootstrap(LoggingFactory.java:31)
at io.dropwizard.Application.<clinit>(Application.java:20)
That is caused by the dropwizard code trying to do that cast. For some
reason, in that scenario only, slf4j's getLogger returns
org.slf4j.impl.SimpleLogger. I checked my classpath/dependencies to make
sure I don't include the slf4j-simple jar anywhere. The only slf4j bindings
I have is the native logback implementation, which comes with dropwizard.
No slf4j-simple jar, no org.slf4j.impl.SimpleLogger on my classpath. So how
come it shows up in the runtime when running from maven?

I even tried to strip the project down completely. I removed dropwizard,
and just left slf4-api, logback and jbehave. The JBehave test was modified
to just print out the class name of the logger retrieved by the same
getLogger method.
And same result again - SimpleLogger (slf4j-simple) when running from
maven, logback logger when running from the IDE.

To prove it's somehow JBehave related, I created a plain junit test (no
jbehave), which just prints out the logger's class name. It always returns
the right logback Logger, when run from eclipse or maven.

So it seems to be only maven-JBehave combination which always results with
slf4j-simple binding. That makes me think that JBehave (or actually its
maven plugin) could be doing something (dodgy?) log related under the hood.
Could somebody confirm that? And if so, does anybody know a good
workaround? Apart from Cucumber, of course :)

Any help is much appreciated.

Thanks,
Dariusz

Reply via email to