regu
regu

Reputation: 55

How to configure Logback's ContextInitializer?

In versions 1.3.8 and earlier of Logback, it was possible to configure the ContextInitializer using a resource file using its configureByResource method, e.g.

new ContextInitializer(loggerContext).configureByResource(
            Thread.currentThread().getContextClassLoader().getResource("pattern-console-logback.xml"));

In version >=1.3.9, this method completely disappeared. How then can I achieve the same configuration ?

The autoConfig method doesn't provide what I need. The flavour using a classLoader is a bit obscure to me as I wasn't able to find any example or way to use it properly.

Upvotes: 0

Views: 178

Answers (1)

Daniel A.A. Pelsmaeker
Daniel A.A. Pelsmaeker

Reputation: 50326

From looking at this commit, I guess the new way would be:

URL url = Thread.currentThread().getContextClassLoader().getResource("pattern-console-logback.xml");

DefaultJoranConfigurator joranConfigurator = new DefaultJoranConfigurator();
joranConfigurator.setContext(loggerContext);
joranConfigurator.configureByResource(url);

Upvotes: 0

Related Questions