Hi all,<div><br></div><div>I am trying to configure Logback programmatically to write logs into an OutputStream. </div><div><br></div><div>The following libraries are in my classpath:</div><div>* logback-core-1.0.6.jar</div>
<div>* logback-classic-1.0.6.jar</div><div>* slf4j-api-1.6.4.jar</div><div><br></div><div>In fact, I _do_ get the logs in the console, which tells me that Logback has started with the default configuration of outputting to the Console.</div>
<div><br></div><div>What I want, however, is to programmatically add an appender to a Logger, so that it also outputs to an OutputStream.</div><div><br></div><div>The following snippet shows what I am doing, and the result is only writing logs to the Console:</div>
<div><br></div><div>Any ideas what I'm doing wrong?</div><div><br></div><div><div>







<p class="p1"><span class="Apple-tab-span">     </span><span class="s1">private</span> <span class="s1">static</span> ByteArrayOutputStream <span class="s2">baos</span> = <span class="s1">new</span> ByteArrayOutputStream(100000000);</p>

<p class="p2"><span class="Apple-tab-span">     </span></p>
<p class="p3">...</p><p class="p3">private void method() {</p><p class="p3">OutputStreamAppender<ILoggingEvent> logbackAppender = <span class="s1">new</span> OutputStreamAppender<ILoggingEvent>();</p>
<p class="p1"><span class="Apple-tab-span">     </span><span class="Apple-tab-span">      </span>LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();</p>
<p class="p2"><span class="Apple-tab-span">     </span><span class="Apple-tab-span">      </span></p>
<p class="p1"><br></p><p class="p1"><span class="Apple-tab-span">   </span><span class="Apple-tab-span">      </span>PatternLayoutEncoder encoder = <span class="s1">new</span> PatternLayoutEncoder();</p>
<p class="p1"><span class="Apple-tab-span">     </span><span class="Apple-tab-span">      </span>encoder.setContext(lc);</p>
<p class="p5"><span class="s3"><span class="Apple-tab-span">    </span><span class="Apple-tab-span">      </span>encoder.setPattern(</span>"%-5level [%thread]: %message%n"<span class="s3">);</span></p>
<p class="p1"><br></p>
<p class="p2"><span class="Apple-tab-span">     </span><span class="Apple-tab-span">      </span></p>
<p class="p1"><span class="Apple-tab-span">     </span><span class="Apple-tab-span">      </span>logbackAppender.setContext(lc);</p>
<p class="p5"><span class="s3"><span class="Apple-tab-span">    </span><span class="Apple-tab-span">      </span>logbackAppender.setName(</span>"Output stream logback appender"<span class="s3">);</span></p>
<p class="p1"><span class="Apple-tab-span">     </span><span class="Apple-tab-span">      </span>logbackAppender.setOutputStream(<span class="s2">baos</span>);</p>
<p class="p6">logbackAppender.setEncoder(encoder);</p>
<p class="p2"><span class="Apple-tab-span">     </span><span class="Apple-tab-span">      </span></p></div><div><br></div><div>LOGGER.addAppender(logbackAppender);</div><div><br></div><div>LOGGER.debug("This");</div><div>
LOGGER.info("can't be");</div><div>LOGGER.info("happening")</div><div><br></div>}</div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div>-- <br>Sent from my iPhone<br>

</div>