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