Reputation: 55
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
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