Hi all,
I am trying to configure Logback programmatically to write logs into an OutputStream.
The following libraries are in my classpath:
* logback-core-1.0.6.jar
* logback-classic-1.0.6.jar
* slf4j-api-1.6.4.jar
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.
What I want, however, is to programmatically add an appender to a Logger, so that it also outputs to an OutputStream.
The following snippet shows what I am doing, and the result is only writing logs to the Console:
Any ideas what I'm doing wrong?
private static ByteArrayOutputStream baos = new ByteArrayOutputStream(100000000);
...
private void method() {
OutputStreamAppender<ILoggingEvent> logbackAppender = new OutputStreamAppender<ILoggingEvent>();
LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
PatternLayoutEncoder encoder = new PatternLayoutEncoder();
encoder.setContext(lc);
encoder.setPattern("%-5level [%thread]: %message%n");
logbackAppender.setContext(lc);
logbackAppender.setName("Output stream logback appender");
logbackAppender.setOutputStream(baos);
logbackAppender.setEncoder(encoder);
LOGGER.addAppender(logbackAppender);
LOGGER.debug("This");
LOGGER.info("can't be");
LOGGER.info("happening")
}
--
Sent from my iPhone