It is currently impossible to override an existing logback.groovy configuration file with either logback-test.groovy (currently not considered at all) or logback-test-xml.
The reason for this is located in the method ContextInitializer.findURLOfDefaultConfigurationFile which prefers Groovy over XML in general:
public URL findURLOfDefaultConfigurationFile(boolean updateStatus) {
ClassLoader myClassLoader = Loader.getClassLoaderOfObject(this);
URL url = "" updateStatus);
if (url != null) {
return url;
}
url = "" myClassLoader, updateStatus);
if (url != null) {
return url;
}
url = "" myClassLoader, updateStatus);
if (url != null) {
return url;
}
return getResource(AUTOCONFIG_FILE, myClassLoader, updateStatus);
}
I'd suggest to change it like this:
public static final String GROOVY_TEST_AUTOCONFIG_FILE = "logback-test.groovy";
public URL findURLOfDefaultConfigurationFile(boolean updateStatus) {
ClassLoader myClassLoader = Loader.getClassLoaderOfObject(this);
URL url = "" updateStatus);
if (url != null) {
return url;
}
url = "" myClassLoader, updateStatus);
if (url != null) {
return url;
}
url = "" myClassLoader, updateStatus);
if (url != null) {
return url;
}
url = "" myClassLoader, updateStatus);
if (url != null) {
return url;
}
return getResource(AUTOCONFIG_FILE, myClassLoader, updateStatus);
}
or at least into this if overriding configuration via logback-test.groovy is intentionally left out for reasons unknown to me:
public URL findURLOfDefaultConfigurationFile(boolean updateStatus) {
ClassLoader myClassLoader = Loader.getClassLoaderOfObject(this);
URL url = "" updateStatus);
if (url != null) {
return url;
}
url = "" myClassLoader, updateStatus);
if (url != null) {
return url;
}
url = "" myClassLoader, updateStatus);
if (url != null) {
return url;
}
return getResource(AUTOCONFIG_FILE, myClassLoader, updateStatus);
}
That way a -test Logback configuration would always be preferred over one without -test.
|