[logback-user] Problem with configuring logback programatically

Shahar.Kedar at thomsonreuters.com Shahar.Kedar at thomsonreuters.com
Sun Feb 27 17:50:46 CET 2011


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.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://qos.ch/pipermail/logback-user/attachments/20110227/ff3c8687/attachment-0001.html>


More information about the Logback-user mailing list