Thank you both for the answer. You were right, after removing the cast everything works just fine. I never though it would be the reason because, at the time, I looked on how to use a logger in Scala and that was the answer I found (possibly on stackoverflow)
2015-08-03 11:00 GMT+01:00 <slf4j-user-requ...@qos.ch>: > Send slf4j-user mailing list submissions to > slf4j-user@qos.ch > > To subscribe or unsubscribe via the World Wide Web, visit > http://mailman.qos.ch/mailman/listinfo/slf4j-user > or, via email, send a message with subject or body 'help' to > slf4j-user-requ...@qos.ch > > You can reach the person managing the list at > slf4j-user-ow...@qos.ch > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of slf4j-user digest..." > > > Today's Topics: > > 1. can't understand cast error (pedro rijo) > 2. Re: can't understand cast error (Joachim Durchholz) > 3. usubscribe (Jim Weaver) > > > ---------------------------------------------------------------------- > > Message: 1 > Date: Sun, 2 Aug 2015 18:40:46 +0100 > From: pedro rijo <pedrorij...@gmail.com> > To: slf4j-user@qos.ch > Subject: [slf4j-user] can't understand cast error > Message-ID: > <CAPMsMoAeCPmgp6Jn5et-zG7J= > y5ohma73zh_7zdj2jl0tbu...@mail.gmail.com> > Content-Type: text/plain; charset="utf-8" > > Hey, > > I'm not sure if this is a logback or slf4j issue, so sorry if it's a > logback issue. > > My question is posted on stackoverflow ( > > http://stackoverflow.com/questions/31772577/org-slf4j-helpers-substitutelogger-cannot-be-cast-to-ch-qos-logback-classic-logg > ) but I will paste it here: > > I've seen some questions very similar to this one ( > > http://stackoverflow.com/questions/15483309/org-slf4j-helpers-noploggerfactory-cannot-be-cast-to-ch-qos-logback-classic-logg) > ), > but none of them received a good answer, or at least one that explained or > solved this problem > > I was able to create a very small project (basically 2 Scala classes - each > with a logger - and 2 test classes) with a similar structure to my real > project where I found the problem. The example is available here: > https://bitbucket.org/pedrorijo91/logger-exp > > The problem happens when I run `sbt test`, resulting in the following > error: > > {14:43:41} (#47) ~/Desktop/logger-exp/log-exp@pedrorijo(master) $ sbt > test > Java HotSpot(TM) 64-Bit Server VM warning: ignoring option > MaxPermSize=384m; support was removed in 8.0 > [info] Loading global plugins from /Users/pedrorijo/.sbt/0.13/plugins > [info] Loading project definition from > /Users/pedrorijo/Desktop/git/scala/logger-exp/log-exp/project > [info] Set current project to log-exp (in build > file:/Users/pedrorijo/Desktop/git/scala/logger-exp/log-exp/) > [info] HelloTest: > [info] Exception encountered when attempting to run a suite with class > name: HelloTest *** ABORTED *** > [info] java.lang.ExceptionInInitializerError: > [info] at HelloTest$$anonfun$1.apply$mcV$sp(HelloTest.scala:8) > [info] at HelloTest$$anonfun$1.apply(HelloTest.scala:8) > [info] at HelloTest$$anonfun$1.apply(HelloTest.scala:8) > [info] at > > org.scalatest.Transformer$$anonfun$apply$1.apply$mcV$sp(Transformer.scala:22) > [info] at org.scalatest.OutcomeOf$class.outcomeOf(OutcomeOf.scala:85) > [info] at org.scalatest.OutcomeOf$.outcomeOf(OutcomeOf.scala:104) > [info] at org.scalatest.Transformer.apply(Transformer.scala:22) > [info] at org.scalatest.Transformer.apply(Transformer.scala:20) > [info] at > org.scalatest.FunSuiteLike$$anon$1.apply(FunSuiteLike.scala:166) > [info] at org.scalatest.Suite$class.withFixture(Suite.scala:1122) > [info] ... > [info] Cause: java.lang.ClassCastException: > org.slf4j.helpers.SubstituteLogger cannot be cast to > ch.qos.logback.classic.Logger > [info] at com.example.Hello$.<init>(Hello.scala:8) > [info] at com.example.Hello$.<clinit>(Hello.scala) > [info] at HelloTest$$anonfun$1.apply$mcV$sp(HelloTest.scala:8) > [info] at HelloTest$$anonfun$1.apply(HelloTest.scala:8) > [info] at HelloTest$$anonfun$1.apply(HelloTest.scala:8) > [info] at > > org.scalatest.Transformer$$anonfun$apply$1.apply$mcV$sp(Transformer.scala:22) > [info] at org.scalatest.OutcomeOf$class.outcomeOf(OutcomeOf.scala:85) > [info] at org.scalatest.OutcomeOf$.outcomeOf(OutcomeOf.scala:104) > [info] at org.scalatest.Transformer.apply(Transformer.scala:22) > [info] at org.scalatest.Transformer.apply(Transformer.scala:20) > [info] ... > SLF4J: The following set of substitute loggers may have been accessed > SLF4J: during the initialization phase. Logging calls during this > SLF4J: phase were not honored. However, subsequent logging calls to > these > SLF4J: loggers will work as normally expected. > SLF4J: See also http://www.slf4j.org/codes.html#substituteLogger > SLF4J: com.example.Hello$ > 14:43:52.846 [pool-6-thread-4-ScalaTest-running-WorldTest] INFO > com.example.World$ - LOGGING > [info] WorldTest: > [info] - test > [info] Run completed in 456 milliseconds. > [info] Total number of tests run: 1 > [info] Suites: completed 1, aborted 1 > [info] Tests: succeeded 1, failed 0, canceled 0, ignored 0, pending 0 > [info] *** 1 SUITE ABORTED *** > [error] Error during tests: > [error] HelloTest > [error] (test:test) sbt.TestsFailedException: Tests unsuccessful > [error] Total time: 1 s, completed Aug 2, 2015 2:43:52 PM > > > but if I run each of the tests individually through: > > `sbt "testOnly HelloTest"` and `sbt "testOnly WorlTest"` I get no error. > > As far as I've seen this is not just a Scala issue, it seems that in Java > is also possible to happen. Furthermore, I've read that during > initialization the loggers are substituted by a Substitute Logger ( > http://www.slf4j.org/codes.html#substituteLogger). > > But I can't understand: > > 1. why it only happens in tests, and when running both tests? > 2. why it happens? > 3. how to debug/solve this problem? > > As I said before, I've created a repository with a working example > (working, meaning with the error happening) here: > https://bitbucket.org/pedrorijo91/logger-exp > > > > -- > Kind Regards, > > Pedro Rijo > -------------- next part -------------- > An HTML attachment was scrubbed... > URL: < > http://mailman.qos.ch/pipermail/slf4j-user/attachments/20150802/5a5260bf/attachment-0001.html > > > > ------------------------------ > > Message: 2 > Date: Sun, 02 Aug 2015 21:32:51 +0200 > From: Joachim Durchholz <j...@durchholz.org> > To: slf4j-user@qos.ch > Subject: Re: [slf4j-user] can't understand cast error > Message-ID: <55be7063.9060...@durchholz.org> > Content-Type: text/plain; charset=windows-1252; format=flowed > > Am 02.08.2015 um 19:40 schrieb pedro rijo: > > As I said before, I've created a repository with a working example > > (working, meaning with the error happening) here: > > https://bitbucket.org/pedrorijo91/logger-exp > > I don't know why it's throwing an error with two tests but working with > just one, but the type cast is definitely wrong - you're trying to force > it into a ch.qos.logback.classic.Logger, but LoggerFactory will give you > an org.slf4j.Logger. > You work with ch.qos.logback.classic.Logger when implementing a logger, > an appender or anything else in the logging machinery, or possibly > during logging setup, but not when sending log messages. Code that > merely creates log messages should work with org.slf4j.Logger. > > > ------------------------------ > > Message: 3 > Date: Sun, 2 Aug 2015 15:27:10 -0500 > From: Jim Weaver <weaver...@gmail.com> > To: slf4j-user@qos.ch > Subject: [slf4j-user] usubscribe > Message-ID: > < > camgnyyhybhc35zfjeka-repd8i_0c7fdqp2ozdkwqoytqc+...@mail.gmail.com> > Content-Type: text/plain; charset="utf-8" > > > -------------- next part -------------- > An HTML attachment was scrubbed... > URL: < > http://mailman.qos.ch/pipermail/slf4j-user/attachments/20150802/7934943e/attachment-0001.html > > > > ------------------------------ > > Subject: Digest Footer > > _______________________________________________ > slf4j-user mailing list > slf4j-user@qos.ch > http://mailman.qos.ch/mailman/listinfo/slf4j-user > > ------------------------------ > > End of slf4j-user Digest, Vol 41, Issue 1 > ***************************************** > -- Obrigado, Pedro Rijo
_______________________________________________ slf4j-user mailing list slf4j-user@qos.ch http://mailman.qos.ch/mailman/listinfo/slf4j-user