Hello.<br><br>I am trying to implement logback/slf4j and an extremely frustrating thing is occurring when I run my unit tests. All of the log messages are being duplicated. I am aware of the whole additive nature of appenders and I am pretty sure that I am doing things correctly in that regard but the messages continue to duplicate when running unit tests. When I run through a main method, they do not. Here is my configuration and the messages that are displayed when running unit tests.<br>
<br>Dependencies I have included (via Ivy):<br><br><span style="font-family:courier new,monospace"><dependency org="org.slf4j" name="slf4j-api" rev="1.6.4"/></span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace"><dependency org="ch.qos.logback" name="logback-core" rev="1.0.0"/></span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"><dependency org="ch.qos.logback" name="logback-classic" rev="1.0.0"/></span><br>
<br>Configuration:<br><br><span style="font-family:courier new,monospace"><configuration debug="true"> </span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> <contextName>example-test</contextName></span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace"> <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> </span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> <encoder></span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace"> <pattern>%d{HH:mm:ss.SSS} %-5level %logger - %msg%n</pattern></span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> </encoder></span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace"> </appender></span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> <logger name="com.example" level="debug"/></span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace"> <root level="warn"></span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> <appender-ref ref="STDOUT"/></span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace"> </root></span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"></configuration></span><br><br>Log output when running unit tests:<br>
<br><span style="font-family:courier new,monospace">13:44:23,308 |-INFO in ch.qos.logback.classic.joran.action.ContextNameAction - Setting logger context name as [example-test]</span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace">13:44:23,308 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.ConsoleAppender]</span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace">13:44:23,313 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [STDOUT]</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">13:44:23,344 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property</span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace">13:44:23,431 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [com.example] to DEBUG</span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace">13:44:23,431 |-INFO in ch.qos.logback.classic.joran.action.RootLoggerAction - Setting level of ROOT logger to WARN</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">13:44:23,431 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [STDOUT] to Logger[ROOT]</span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace">13:44:23,433 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - End of configuration.</span><br style="font-family:courier new,monospace"><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace">13:44:23.453 INFO com.example.project.service.impl.ExampleClassImpl - This is a test.</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">13:44:23.466 INFO com.example.project.service.impl.ExampleClassImpl - This is a test.</span><br>
<br>Log output when running under main method:<br><br><span style="font-family:courier new,monospace">13:48:16,729 |-INFO in ch.qos.logback.classic.joran.action.ContextNameAction - Setting logger context name as [example-test]</span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace">13:48:16,729 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.ConsoleAppender]</span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace">13:48:16,734 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [STDOUT]</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">13:48:16,760 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property</span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace">13:48:16,825 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [com.example] to DEBUG</span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace">13:48:16,825 |-INFO in ch.qos.logback.classic.joran.action.RootLoggerAction - Setting level of ROOT logger to WARN</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">13:48:16,825 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [STDOUT] to Logger[ROOT]</span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace">13:48:16,827 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - End of configuration.</span><br style="font-family:courier new,monospace"><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace">13:48:16.843 INFO com.example.project.service.impl.ExampleClassImpl - This is a test.</span><br><br>I know that the unit tests are picking up my configuration correctly. When I examine my unit test results, I can see that tests are only being run once so I it is not a duplicate execution of the code. Is there anything special I have to do to stop the duplicates when running unit tests? Thanks for your help.<br>
<br>--Matt--<br>