The following code with no logback configuration on the classpath:
import ch.qos.logback.classic.LoggerContext;
import org.slf4j.LoggerFactory;
import java.net.MalformedURLException;
import java.net.URL;
public class Main {
public static void main(String[] args) {
LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
lc.setPackagingDataEnabled(true);
try {
new URL("foo");
} catch (MalformedURLException e) {
LoggerFactory.getLogger("com.example.Main").warn("An exception!", e);
}
}
}
does not print packaging data in the stacktrace (note that this is the way described in the documentation for packagingData).
To get the packaging data you need to create a logback.xml with packagingData="true" (as in the documentation). With this file on the classpath, calling lc.setPackagingDataEnabled(false); has effect and disables packaging data. Setting false in XML and true in code does not show packaging data.
|