I know how to set the log level via environment variables and application properties.
Is there a way to set them programmatically?
I would like to set log levels for particular test classes (which are using SpringJUnit4ClassRunner
and @SpringApplicationConfiguration
), but not all of them, and without having a separate properties file for every combination.
I tried defining a non-lazy bean to add a new PropertySource
to the environment; the method was called but it had no effect.
@Bean
@Lazy(false)
public PropertySource testProperties(ConfigurableEnvironment environment) {
PropertySource properties = new MapPropertySource("testProperties", Collections.singletonMap(
"logging.level.org.springframework.security", "DEBUG"
));
environment.getPropertySources().addFirst(properties);
return properties;
}