The appender.setLayout(patternLayout); call generates a warning. However, at that time the appender does not know its context.

Change
 appender.setLayout(patternLayout);
 appender.setContext(lc);
to
 appender.setContext(lc);
 appender.setLayout(patternLayout);

In which case you will get the warning message:

|-WARN - This appender no longer admits a layout as a sub-component, set an encoder instead. |-WARN - To ensure compatibility, wrapping your layout in LayoutWrappingEncoder. |-WARN - See also http://logback.qos.ch/codes.html#layoutInsteadOfEncoder for details

Visit http://logback.qos.ch/codes.html#layoutInsteadOfEncoder for further instructions.
HTH,
--
Ceki

On 27/02/2011 5:50 PM, [email protected] wrote:
Hi,

I’m using logback 0.9.28 and I’m trying to configure logback
programmatically with the following code:

public void prepare() {

LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();

lc.reset();

lc.getLogger("com").setLevel(Level.DEBUG);

lc.getLogger("com.example").setLevel(Level.DEBUG);

lc.getLogger("com.example.test").setLevel(Level.DEBUG);

lc.getLogger("com.example.test.inner").setLevel(Level.DEBUG);

PatternLayout patternLayout = new PatternLayout();

patternLayout.setContext(lc);

patternLayout.setPattern("%-5level %logger - %msg%n");

patternLayout.start();

ConsoleAppender<ILoggingEvent> appender = new
ConsoleAppender<ILoggingEvent>();

appender.setLayout(patternLayout);

appender.setContext(lc);

appender.start();

lc.getLogger("root").addAppender(appender);

lc.start();

StatusPrinter.printInCaseOfErrorsOrWarnings(lc);

super.prepare(testCase);

}

I keep getting the following message: LOGBACK: No context given for
ch.qos.logback.core.ConsoleAppender[null].

I’m seeing the log messages in the console, but I fail to understand why
I’m getting this message.

Thanks,

Shahar


This email was sent to you by Thomson Reuters, the global news and
information company.
Any views expressed in this message are those of the individual sender,
except where the sender specifically states them to be the views of
Thomson Reuters.



--
QOS.ch, main sponsor of cal10n, logback and slf4j open source projects, is looking to hire talented software developers. If interested, please email your resume to [email protected].
_______________________________________________
Logback-user mailing list
[email protected]
http://qos.ch/mailman/listinfo/logback-user

Reply via email to